"use client"; import Link from "next/link"; import { useState } from "react"; import { refreshAllChannelSnapshotsAction, type RefreshAllResult, } from "../actions"; type Status = | { kind: "idle" } | { kind: "running" } | { kind: "done"; result: RefreshAllResult } | { kind: "error"; message: string }; export function RefreshAllReportsButton() { const [status, setStatus] = useState({ kind: "idle" }); async function handleClick() { setStatus({ kind: "running" }); try { const result = await refreshAllChannelSnapshotsAction(); setStatus({ kind: "done", result }); } catch (e) { setStatus({ kind: "error", message: (e as Error).message }); } } const running = status.kind === "running"; return ( // See SyncAllChannelsButton: an outline, and a result span that wraps to // its own line rather than stretching the header cluster.
{status.kind === "done" && ( `${s.slug}: ${s.reason}`) .join("\n") } > Queued {status.result.queued.length} · skipped{" "} {status.result.skipped.length} ·{" "} view jobs )} {status.kind === "error" && ( {status.message} )}
); }