import { useMemo, useRef } from 'react';
import { useLibraryQuery } from '@sd/client';
import { Button, SelectOption } from '@sd/ui';
import { DummyKey, Key } from './Key';
// ideal for going within a select box
// can use mounted or unmounted keys, just provide different inputs
export const KeyListSelectOptions = (props: { keys: string[] }) => (
<>
{props.keys.map((key) => (
Key {key.substring(0, 8).toUpperCase()}
))}
>
);
export default () => {
const keys = useLibraryQuery(['keys.list']);
const mountedUuids = useLibraryQuery(['keys.listMounted']);
const defaultKey = useLibraryQuery(['keys.getDefault']);
const mountingQueue = useRef(new Set());
const [mountedKeys, unmountedKeys] = useMemo(
() => [
keys.data?.filter((key) => mountedUuids.data?.includes(key.uuid)) ?? [],
keys.data?.filter((key) => !mountedUuids.data?.includes(key.uuid)) ?? []
],
[keys, mountedUuids]
);
if (keys.data?.length === 0) {
return (
);
}
return (
<>
{[...mountedKeys, ...unmountedKeys]?.map((key) => (
))}
>
);
};