import { batch, createEffect, createMemo, createSignal, For, Show, untrack, type Accessor, type Setter, } from "solid-js"; import "./DownloadManager.css"; import "./Dialog.css"; import "toastify-js/src/toastify.css"; import { formatBytes } from "../utils"; import { ClearSVG, RefreshSVG, StopSVG } from "./SVG"; import { type DownloadStatus, downloadStatusMap, setDownloadStatusMap, type Progress } from "../offline"; import { createStore } from "solid-js/store"; interface DownloadManagerProps { showDownloadManager: Accessor; setShowDownloadManager: Setter; } export default function DownloadManager(props: DownloadManagerProps) { let dialogElement!: HTMLDialogElement; createEffect(() => { if (props.showDownloadManager()) { dialogElement.showModal(); } }); function handleClose() { dialogElement.close(); props.setShowDownloadManager(false); } const downloadItems = createMemo(() => { return Object.entries(downloadStatusMap).filter(([_path, status]) => isProgress(status)); }); function isProgress(status: DownloadStatus | undefined): status is Progress { return status !== undefined && typeof status === "object" && "status" in status; } return ( e.target.nodeName === "DIALOG" && handleClose()} >
Download

{([path, status]) => { if (!isProgress(status)) return; const [showReason, setShowReason] = createSignal(false); return (
{path}
{status && typeof status.status === "number" ? ( <> {formatBytes(status.status)} ) : ( <> {(status.status === "Failed" && ( )) || "Aborted"} )}
{"reason" in status && status.reason}
); }}
); }