import { api } from "@/lib/api" import { useJobs, useQueryClient, qk } from "@/lib/queries" import { useDialog } from "@/lib/useDialog" import { cn } from "@/lib/utils" import { fmtBytes, fmtEta } from "@/lib/format" export function JobsBar() { const qc = useQueryClient() const { data: jobs = [] } = useJobs(2_000) const { showAlert, dialogElement } = useDialog() async function cancelJob(jobId: string) { try { await api(`/api/jobs/${jobId}/cancel`, { method: "POST" }) qc.invalidateQueries({ queryKey: qk.jobs }) } catch (e: any) { showAlert("Fehler", e.message) } } const active = jobs.filter((j) => j.state === "running" || j.state === "queued") const recent = jobs.filter((j) => j.state !== "running" && j.state !== "queued").slice(-3) if (active.length === 0 && recent.length === 0) return null return (
Aktive Downloads
{active.map((j) => (
{j.label}
{j.progress ?? 0}% • {fmtBytes(j.done_bytes)}/{fmtBytes(j.total_bytes)} {j.eta_s ? ` • ETA ${fmtEta(j.eta_s)}` : ""}
))} {recent.map((j) => (
{j.label} {j.state}
))} {dialogElement}
) }