Files
spacedrive/interface/app/$libraryId/settings/library/keys/KeyViewerDialog.tsx
Vítor Vasconcellos 0d3805339e [ENG-591] - Fix some funky behaviors (#827)
* WIP

* Some minor fixes for light theme
 - Fix `useIsDark` not reading the initial theme value (only reacting to theme changes)
 - Fix `Inspector` always showing a dark image when no item was selected
 - Fix `Thumb` video extension using black text on light theme

* Improve form error messages
 - Fix `addLocationDialog` not registering the path input
 - Remove `@hookform/error-message`

* Fix Dialog not respecting max-width
 - Fix ErrorMessage animation jumping

* A lot of misc fixes
 - Implement an `useExplorerItemData` (cleaner fix for thumbnail flicker)
 - Fix broken image showing for `Thumb` due a rece condition when props are updated
 - Implement an `ExternalObject` component that hacks an alternative for `onLoad` and `onError` events for <object>
 - Fix `Overview` broken layout when `Inspector` is open and window is small
 - Improve `IndexerRuleEditor` UX in `AddLocationDialog`
 - Improve the way `IndexerRuleEditor` handles rules deletion
 - Fix `IndexerRuleEditor` closing the the new rule form even when the rule creation fails
 - Add an editable prop to `IndexerRuleEditor` to disable all editable functions
 - Fix `getIcon` fallbacking to Document instead of the dark version of an icon if it exists
 - Add some missing colors to white theme

* Format

* Fix Backup restore key dialog not resetting after error

* Feedback

* Format

* Normalize imports

* Fix ColorPicker export

* Fix Thumb video ext not showing in MediaView with show square thumbnails
 - Fix AddLocationDialog Error resetting when changing IndexRules
2023-05-20 03:11:10 +00:00

161 lines
4.3 KiB
TypeScript

import { Buffer } from 'buffer';
import { Clipboard } from 'phosphor-react';
import { useState } from 'react';
import { slugFromHashingAlgo, useLibraryQuery } from '@sd/client';
import { Button, Dialog, Input, Select, SelectOption, UseDialogProps, useDialog } from '@sd/ui';
import { useZodForm } from '@sd/ui/src/forms';
import { KeyListSelectOptions } from '~/app/$libraryId/KeyManager/List';
export const KeyUpdater = (props: {
uuid: string;
setKey: (value: string) => void;
setEncryptionAlgo: (value: string) => void;
setHashingAlgo: (value: string) => void;
setContentSalt: (value: string) => void;
}) => {
useLibraryQuery(['keys.getKey', props.uuid], {
onSuccess: (data) => {
props.setKey(data);
}
});
const keys = useLibraryQuery(['keys.list']);
const key = keys.data?.find((key) => key.uuid == props.uuid);
if (key) {
props.setEncryptionAlgo(key?.algorithm);
props.setHashingAlgo(slugFromHashingAlgo(key?.hashing_algorithm));
props.setContentSalt(Buffer.from(key.content_salt).toString('hex'));
}
return <></>;
};
export default (props: UseDialogProps) => {
const keys = useLibraryQuery(['keys.list'], {
onSuccess: (data) => {
if (key === '' && data.length !== 0) {
setKey(data[0]?.uuid ?? '');
}
}
});
const [key, setKey] = useState('');
const [keyValue, setKeyValue] = useState('');
const [contentSalt, setContentSalt] = useState('');
const [encryptionAlgo, setEncryptionAlgo] = useState('');
const [hashingAlgo, setHashingAlgo] = useState('');
return (
<Dialog
form={useZodForm()}
dialog={useDialog(props)}
title="View Key Values"
description="Here you can view the values of your keys."
ctaLabel="Done"
>
<KeyUpdater
uuid={key}
setKey={setKeyValue}
setEncryptionAlgo={setEncryptionAlgo}
setHashingAlgo={setHashingAlgo}
setContentSalt={setContentSalt}
/>
<div className="mb-3 mt-4 grid w-full gap-4">
<div className="flex flex-col">
<span className="text-xs font-bold">Key</span>
<Select
className="mt-2 grow"
value={key}
onChange={(e) => {
setKey(e);
}}
>
{keys.data && (
<KeyListSelectOptions keys={keys.data.map((key) => key.uuid)} />
)}
</Select>
</div>
</div>
<div className="mb-3 mt-4 grid w-full grid-cols-2 gap-4">
<div className="flex flex-col">
<span className="text-xs font-bold">Encryption</span>
<Select
className="mt-2 w-[150px] text-gray-300"
value={encryptionAlgo}
disabled
onChange={() => {}}
>
<SelectOption value="XChaCha20Poly1305">XChaCha20-Poly1305</SelectOption>
<SelectOption value="Aes256Gcm">AES-256-GCM</SelectOption>
</Select>
</div>
<div className="flex flex-col">
<span className="text-xs font-bold">Hashing</span>
<Select
className="mt-2 text-gray-300"
value={hashingAlgo}
disabled
onChange={() => {}}
>
<SelectOption value="Argon2id-s">Argon2id (standard)</SelectOption>
<SelectOption value="Argon2id-h">Argon2id (hardened)</SelectOption>
<SelectOption value="Argon2id-p">Argon2id (paranoid)</SelectOption>
<SelectOption value="BalloonBlake3-s">
BLAKE3-Balloon (standard)
</SelectOption>
<SelectOption value="BalloonBlake3-h">
BLAKE3-Balloon (hardened)
</SelectOption>
<SelectOption value="BalloonBlake3-p">
BLAKE3-Balloon (paranoid)
</SelectOption>
</Select>
</div>
</div>
<div className="mb-3 mt-4 grid w-full gap-4">
<div className="flex flex-col">
<span className="mb-2 text-xs font-bold">Content Salt (hex)</span>
<Input
value={contentSalt}
disabled
right={
<Button
type="button"
onClick={() => {
navigator.clipboard.writeText(contentSalt);
}}
size="icon"
>
<Clipboard className="h-4 w-4" />
</Button>
}
/>
</div>
</div>
<div className="mb-3 mt-4 grid w-full gap-4">
<div className="flex flex-col">
<span className="mb-2 text-xs font-bold">Key Value</span>
<Input
value={keyValue}
disabled
right={
<Button
type="button"
onClick={() => {
navigator.clipboard.writeText(keyValue);
}}
size="icon"
>
<Clipboard className="h-4 w-4" />
</Button>
}
/>
</div>
</div>
</Dialog>
);
};