"use client"; import { useEffect, useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import { Button } from "yt-dlp-transcript-common/components/ui/button"; import { frameRederiveAction } from "../frameScanActions"; // "Re-derive (no model)": the scan's timeline worked out again from the // readings it holds — no model, no frame — as `archilyzer frames rederive` // does. The hero's screen name may be changed with it (the derivation reads // the hero's pots, all-ins and bust by name). export function FrameRederiveControl({ slug, videoId, profile, hero, }: { slug: string; videoId: string; profile: string; hero: string | null; }) { const router = useRouter(); const [hydrated, setHydrated] = useState(false); useEffect(() => setHydrated(true), []); const [name, setName] = useState(hero ?? ""); const [pending, start] = useTransition(); const [done, setDone] = useState(null); const [error, setError] = useState(null); const run = () => { setError(null); setDone(null); start(async () => { const res = await frameRederiveAction(slug, videoId, profile, name); if (!res.ok) { setError(res.error); return; } const { before: b, after: a, eventsByKind } = res.rederived; const kinds = Object.entries(eventsByKind) .map(([k, n]) => `${k} ${n}`) .join(", "); setDone( `Re-derived from ${res.rederived.readings} readings: tournaments ${b.tournaments} → ${a.tournaments}, ` + `events ${b.events} → ${a.events}, flags ${b.flags} → ${a.flags}, misreads ${b.misreads} → ${a.misreads}` + (kinds ? ` (${kinds})` : ""), ); router.refresh(); }); }; return (
{done && (

{done}

)} {error && (

{error}

)}
); }