import { Signal, useComputed } from "@preact/signals"; import Button, { button_class } from "@/components/Button.tsx"; import FileInfo from "@/components/FileInfo.tsx"; import { CloseIcon, PlusIcon } from "@/components/Icons.tsx"; import { format_bytes } from "@/src/files.ts"; import { twMerge } from "@/src/tw.ts"; interface FilePickerProps { on_add: (files: File[]) => void; } // Visually hidden, wrap it in a label to open the picker function FilePicker(props: FilePickerProps) { function change(event: Event) { const input = event.currentTarget as HTMLInputElement; const files = Array.from(input.files ?? []); input.value = ""; if (files.length) { props.on_add(files); } } return ; } export interface UploadState { file: File; index: number; count: number; // null while the file is being encrypted progress: number | null; controller: AbortController; } interface UploadingProps { state: UploadState; } function Uploading({ state }: UploadingProps) { const percent = Math.round((state.progress ?? 0) * 100); return (
1 ? `${state.index + 1} of ${state.count}` : undefined} />

{state.progress === null ? "Encrypting..." : `Uploading ${percent}%`}

); } interface HubUploadProps { pending: Signal; upload_state: UploadState | null; error: string; dragging: boolean; on_add: (files: File[]) => void; on_upload: () => void; } export default function HubUpload(props: HubUploadProps) { const total_size = useComputed(() => props.pending.value.reduce((total, file) => total + file.size, 0)); function remove(file: File) { props.pending.value = props.pending.value.filter((pending_file) => pending_file !== file); } if (props.upload_state) { return ; } const error = props.error && ; if (props.pending.value.length === 0) { return ( ); } return (
    {props.pending.value.toReversed().map((file, index) => (
  • remove(file)} > } />
  • ))}

Total size: {format_bytes(total_size.value)}

{error}
); }