import "./DownloadButton.css"; import type { AudioFile, Directory } from "music-server-shared/types"; import { download, signalMap, type SignalMapEntry } from "../offline"; import { createSignal, type Accessor, type Signal } from "solid-js"; import type { AppOptions } from "../types"; import { formatBytes, joinPath } from "../utils"; import { DownloadSVG, RefreshSVG } from "./SVG"; import { LoadingSpinner } from "./LoadingScreen"; interface DownloadButtonProps { item: AudioFile | Directory; currentDir: Accessor; options: Accessor; } export function DownloadButton(props: DownloadButtonProps) { const fullPath = joinPath(props.currentDir(), props.item.name); let signal = signalMap.get(fullPath); if (!signal) { signal = createSignal(); signalMap.set(fullPath, signal); } const [getProgress] = signal; return (
{ event.stopPropagation(); download(props.item, props.currentDir(), props.options()); }} > {(() => { const progress = getProgress(); if (progress === undefined) return ( ); if (progress === "DirectoryProgress") return ; if (progress === "CachedFile") return ( ); if ("bytes" in progress) return {formatBytes(progress.bytes)}; console.log(progress); console.error("Unexpected", progress); })()}
); }