"use client"; import Link from "next/link"; import { useState } from "react"; import { clearAllIncompleteTranscriptsAction, redownloadAllIncompleteTranscriptsAction, type GlobalIncompleteResult, } from "../../lib/actionable/actions"; type Mode = "clear" | "redownload"; type Status = | { kind: "idle" } | { kind: "running"; mode: Mode } | { kind: "done"; mode: Mode; result: GlobalIncompleteResult } | { kind: "error"; message: string }; export function FixAllIncompleteButton() { const [status, setStatus] = useState({ kind: "idle" }); async function run(mode: Mode) { if ( mode === "clear" && !window.confirm( "Delete the truncated audio + transcript for every flagged video across ALL channels and enable the auto-download/transcribe runners? The current partial transcripts are removed and re-fetched. This cannot be undone.", ) ) { return; } setStatus({ kind: "running", mode }); try { const result = mode === "clear" ? await clearAllIncompleteTranscriptsAction() : await redownloadAllIncompleteTranscriptsAction(); setStatus({ kind: "done", mode, result }); } catch (e) { setStatus({ kind: "error", message: (e as Error).message }); } } const running = status.kind === "running"; return (
{status.kind === "done" && ( {status.result.ok ? ( <> {status.mode === "clear" ? "Cleared" : "Queued"}{" "} {status.result.affected} across {status.result.channels} channel {status.result.channels === 1 ? "" : "s"} ·{" "} view jobs ) : ( status.result.error )} )} {status.kind === "error" && ( {status.message} )}
); }