import { useT } from "../i18n"; import { closeUploadBatch, useUploads } from "../uploads"; import { Icon } from "./Icon"; import { formatSize } from "./FileFigure"; /** Progress of running uploads: one box per batch with a bar for the total and one per file. */ export function UploadPanel() { const t = useT(); const batches = useUploads(); if (!batches.length) return null; return (
{batches.map((b) => { const total = b.items.reduce((a, i) => a + i.size, 0); const sent = b.items.reduce((a, i) => a + i.sent, 0); const finished = b.items.filter((i) => i.status === "done" || i.status === "error").length; const running = finished < b.items.length; const pct = (a: number, z: number) => (z ? Math.min(100, Math.round((a / z) * 100)) : 100); return (
{running ? t("upload.running", { done: finished, n: b.items.length }) : t("upload.finished", { n: b.items.length })} {formatSize(sent)} / {formatSize(total)}
{b.items.map((i) => (
{i.name} {i.status === "error" ? i.error : i.status === "wait" ? formatSize(i.size) : `${pct(i.sent, i.size)} %`}
))}
); })}
); }