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 ; } interface HubUploadProps { pending: Signal; 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.pending.value.length === 0) { return ( Drag and drop files or click to select them Select files Files are encrypted in this browser before they're uploaded, the server never sees what's inside. ); } return ( {props.pending.value.toReversed().map((file, index) => ( remove(file)} > } /> ))} Add files Total size: {format_bytes(total_size.value)} Upload ); }
Drag and drop files
or click to select them
Files are encrypted in this browser before they're uploaded, the server never sees what's inside.
Total size: {format_bytes(total_size.value)}