"use client"; import { useCallback, useEffect, useState } from "react"; import { badgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; // --------------------------------------------------------------------------- // THE SOURCE BACKLOG on a report video's page (UI notes item 16): for each // channel the cut cites, " transcribed/listed · held · Prioritize", // from the editor's own snapshot counts (GET /api/report/source-backlog). // Prioritize puts the channel in the editor's focus through its ops action; // "Re-sweep when complete" arms a watch the Inbox fires once the backlog of // every cited channel is done (lib/report/sourceBacklog.mjs). // --------------------------------------------------------------------------- type Row = { slug: string; listed: number | null; held: number | null; transcribed: number | null; undownloaded: number | null; untranscribed: number | null; done: boolean; focused: boolean; clips: number; tier: string | null; error?: string; }; type View = { channels: Row[]; editorError: string | null; watch: { slugs: string[]; armedAt: string; firedAt?: string } | null; watchError: string | null; }; const n = (v: number | null) => (v === null ? "?" : v.toLocaleString("en-US")); const day = (iso: string) => new Date(iso).toLocaleDateString("en-GB", { day: "numeric", month: "short" }); export default function SourceBacklog({ project }: { project: string }) { const [view, setView] = useState(null); const [error, setError] = useState(null); const [said, setSaid] = useState(null); const [busy, setBusy] = useState(false); const load = useCallback(async () => { const r = await fetch(`/api/report/source-backlog?project=${encodeURIComponent(project)}`, { cache: "no-store" }).catch(() => null); const j = r ? ((await r.json().catch(() => null)) as (View & { error?: string }) | null) : null; if (!r?.ok || !j) { setError(j?.error ?? "the backlog could not be read"); return; } setView(j); }, [project]); useEffect(() => { void load(); }, [load]); const post = async (body: Record) => { setBusy(true); setError(null); setSaid(null); try { const r = await fetch("/api/report/source-backlog", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, ...body }) }); const j = (await r.json().catch(() => ({}))) as Record; if (!r.ok) setError(String(j.error ?? `HTTP ${r.status}`)); return r.ok ? j : null; } finally { setBusy(false); await load(); } }; if (!view) return error ?

sources: {error}

: null; if (!view.channels.length) return null; // What the editor archives decides it: a channel it does not answer for is never "done". const allDone = view.channels.filter((c) => !c.error).every((c) => c.done); const w = view.watch; return (

sources

{view.channels.map((c) => ( {c.slug} {c.error ? ( {c.error} ) : c.held === null ? ( no report yet ) : ( {n(c.transcribed)}/{n(c.listed)} transcribed · {n(c.held)} held )} {c.done && complete} {!c.done && !c.error && c.focused && in focus} {!c.done && !c.error && !c.focused && ( )} ))} {w?.firedAt ? ( complete since {day(w.firedAt)} — re-sweep (the Inbox says so) ) : w ? ( re-sweep when complete · watching since {day(w.armedAt)} ) : null} {w ? ( ) : ( !allDone && ( ) )}
{view.editorError &&

the editor did not answer: {view.editorError}

} {view.watchError &&

{view.watchError}

} {error && (

{error}

)} {said &&

{said}

}
); }