82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import { Signal } from "@preact/signals";
|
|
|
|
import Button from "@/components/Button.tsx";
|
|
import FileInfo from "@/components/FileInfo.tsx";
|
|
import { CloseIcon, DownloadIcon } from "@/components/Icons.tsx";
|
|
import { download_blob } from "@/src/files.ts";
|
|
|
|
export interface HubFile {
|
|
id: string;
|
|
name: string;
|
|
size: number;
|
|
uploaded_at: number;
|
|
// TODO: replace with fetching and decrypting from the server once uploads exist
|
|
blob: Blob;
|
|
}
|
|
|
|
const DATE_FORMAT = new Intl.DateTimeFormat(undefined, { dateStyle: "medium" });
|
|
|
|
interface HubFileListProps {
|
|
files: Signal<HubFile[]>;
|
|
}
|
|
|
|
export default function HubFileList(props: HubFileListProps) {
|
|
function remove(file: HubFile) {
|
|
props.files.value = props.files.value.filter((other) => other.id !== file.id);
|
|
}
|
|
|
|
if (props.files.value.length === 0) {
|
|
return (
|
|
<div class="flex h-full w-full flex-col justify-center py-6 md:px-6">
|
|
<h1 class="text-3xl font-bold md:pb-2">Your files, encrypted</h1>
|
|
<p class="mt-6 max-w-sm leading-loose text-gray-800 md:mt-2 dark:text-gray-400">
|
|
Only you can open what you store here. Add some files on the left to get started.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div class="flex h-full min-h-0 w-full flex-col">
|
|
<h1 class="flex-none pb-2 text-lg font-bold">
|
|
Your files{" "}
|
|
<span class="font-normal text-gray-500 dark:text-gray-400">({props.files.value.length})</span>
|
|
</h1>
|
|
<ul class="-mx-2 flex min-h-0 flex-col gap-4 overflow-y-auto p-2">
|
|
{props.files.value.map((file) => (
|
|
<li
|
|
key={file.id}
|
|
class="flex flex-col rounded bg-white p-4 shadow-light dark:border dark:border-gray-700 dark:bg-gray-900"
|
|
>
|
|
<FileInfo
|
|
name={file.name}
|
|
size={file.size}
|
|
detail={DATE_FORMAT.format(file.uploaded_at)}
|
|
action={
|
|
<Button
|
|
variant="link"
|
|
class="flex-none self-start p-1 text-gray-500 hover:text-gray-700 focus:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 dark:focus:text-gray-200"
|
|
title="Delete"
|
|
aria-label={`Delete ${file.name}`}
|
|
onClick={() => remove(file)}
|
|
>
|
|
<CloseIcon class="size-3.5" />
|
|
</Button>
|
|
}
|
|
/>
|
|
<hr class="my-4 w-full border-gray-200 dark:border-gray-700" />
|
|
<Button
|
|
variant="link"
|
|
class="flex items-center gap-2 self-start"
|
|
onClick={() => download_blob(file.blob, file.name)}
|
|
>
|
|
<DownloadIcon class="h-4 w-3" />
|
|
Download
|
|
</Button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|