"use client"; import { useEffect, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; // --------------------------------------------------------------------------- // PLAY AND JUDGE (umtool redesign L4, "What needs you"): a rendered version // played in Play (`?take=`) is judged where it is watched -- Like · Maybe · No, // the Takes page's three verdicts, written through the same route (POST // /api/report/takes/verdict, takes/verdicts.json); pressing the lit one clears // it. The Inbox's "versions to judge" card opens here, and judging drops it. // Its terminal twin: `umtool takes verdict

like|maybe|no|clear`. // --------------------------------------------------------------------------- const VERDICTS = [ { id: "like", label: "Like" }, { id: "maybe", label: "Maybe" }, { id: "no", label: "No" }, ] as const; type Verdict = (typeof VERDICTS)[number]["id"]; export default function VersionVerdict({ project, take }: { project: string; take: string }) { const [verdict, setVerdict] = useState(undefined); const [busy, setBusy] = useState(false); const [err, setErr] = useState(null); useEffect(() => { let live = true; void fetch(`/api/report/takes/verdict?project=${encodeURIComponent(project)}`, { cache: "no-store" }) .then((r) => r.json()) .then((j: { verdicts?: Record }) => live && setVerdict(j.verdicts?.[take]?.verdict ?? null)) .catch(() => live && setVerdict(null)); return () => { live = false; }; }, [project, take]); const judge = async (v: Verdict) => { const next = verdict === v ? null : v; setBusy(true); setErr(null); try { const r = await fetch("/api/report/takes/verdict", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, take, verdict: next }), }); const j = (await r.json().catch(() => ({}))) as { error?: string }; if (!r.ok) throw new Error(j.error ?? `HTTP ${r.status}`); setVerdict(next); } catch (e) { setErr(e instanceof Error ? e.message : String(e)); } finally { setBusy(false); } }; return ( {VERDICTS.map((v) => ( ))} {err && ( {err} )} ); }