mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-21 06:59:17 -04:00
* Fix setup-system breaking in macOS due to unavailable envvar - Remove unused docker build-arg from ffmpeg workflow - Fix Overview Explorer extending below inspector - Fix some left behind formatting problems * Some more formatting
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { Spinner } from 'phosphor-react';
|
|
import { useState } from 'react';
|
|
import { useLibraryMutation, useLibraryQuery } from '@sd/client';
|
|
import { Button, PasswordInput } from '@sd/ui';
|
|
import { showAlertDialog } from '~/components';
|
|
|
|
// TODO: Should be a form
|
|
export default () => {
|
|
const keyringSk = useLibraryQuery(['keys.getSecretKey'], { initialData: '' });
|
|
const isUnlocked = useLibraryQuery(['keys.isUnlocked']);
|
|
const unlockKeyManager = useLibraryMutation('keys.unlockKeyManager', {
|
|
onError: () =>
|
|
showAlertDialog({
|
|
title: 'Unlock Error',
|
|
value: 'The information provided to the key manager was incorrect'
|
|
})
|
|
});
|
|
const isKeyManagerUnlocking = useLibraryQuery(['keys.isKeyManagerUnlocking']);
|
|
|
|
const [masterPassword, setMasterPassword] = useState('');
|
|
|
|
const isUnlocking = unlockKeyManager.isLoading || isKeyManagerUnlocking.data == null;
|
|
|
|
return (
|
|
<div className="w-[350px] space-y-2 p-4">
|
|
<PasswordInput
|
|
placeholder="Master Password"
|
|
value={masterPassword}
|
|
onChange={(e) => setMasterPassword(e.target.value)}
|
|
autoFocus
|
|
disabled={isUnlocking}
|
|
/>
|
|
|
|
<Button
|
|
className="w-full"
|
|
variant="accent"
|
|
disabled={isUnlocking}
|
|
onClick={() => {
|
|
if (masterPassword !== '' && keyringSk.data) {
|
|
unlockKeyManager
|
|
.mutateAsync({
|
|
password: masterPassword,
|
|
secret_key: keyringSk.data
|
|
})
|
|
.then(() => isUnlocked.refetch());
|
|
}
|
|
}}
|
|
>
|
|
{isUnlocking ? (
|
|
<Spinner className="mx-auto h-5 w-5 animate-spin fill-white text-white text-opacity-40" />
|
|
) : (
|
|
'Unlock'
|
|
)}
|
|
</Button>
|
|
</div>
|
|
);
|
|
};
|