import type { Download } from "../types";
import * as api from "../api";
/**
* What is being downloaded, and what just was.
*
* WebKit saves the file on its own and says nothing about it, so without this
* a download is indistinguishable from a click that did nothing.
*/
export default function Downloads({
items,
onDismiss,
}: {
items: Download[];
onDismiss: (id: number) => void;
}) {
if (items.length === 0) return null;
return (
{items.map((d) => (
{d.state === "done" ? (
) : d.state === "failed" ? (
) : (
/* No total to divide by — the webview reports a start and a
finish and nothing between — so this spins rather than fills. */
)}
{d.name}
{d.state === "done"
? "Downloaded"
: d.state === "failed"
? "Download failed"
: d.bytes > 0
? `${formatBytes(d.bytes)} so far`
: "Starting…"}
{d.state === "done" && (
)}