import "./DownloadButton.css"; import type { MediaFile, Directory, FileListing } from "music-server-shared/types"; import { deleteFile, download, downloadStatusMap } from "../offline"; import type { Accessor, ResourceActions } from "solid-js"; import type { AppOptions } from "../types"; import { formatBytes, joinPath } from "../utils"; import { DeleteSVG, RefreshSVG, SyncSVG } from "./SVG"; import { LoadingSpinner } from "./LoadingScreen"; interface DownloadButtonProps { fileName: string; item: MediaFile | Directory; fetchFiles: ResourceActions; isOffline: Accessor; currentDir: Accessor; options: AppOptions; } export function DownloadButton(props: DownloadButtonProps) { const fullPath = joinPath(props.currentDir(), props.fileName); return (
{ event.stopPropagation(); if (!props.isOffline()) download(props.fileName, props.item, props.currentDir(), props.currentDir, props.options, props.fetchFiles); else deleteFile(props.fileName, props.item, props.currentDir(), props.fetchFiles); }} > {(() => { const progress = downloadStatusMap[fullPath]; if (props.isOffline()) { return ( ); } if (progress === undefined) { return ( ); } if (progress === "DirectoryProgress") return ; if (progress === "Synced") { return ( ); } if ("bytes" in progress) return {progress.bytes === 0 ? "Queued..." : formatBytes(progress.bytes)}; console.error("Unexpected", progress); })()}
); }