"use client"; import { useEffect, useState } from "react"; // RENDER MODE on the take panel (common/lib/renderPriority.mjs; AGENTS.md // "Render mode"): the "Give renders the machine" toggle, and a banner while a // render holds the machine. // // The toggle is this browser's: a take this page starts (New take, Make all // styles, a card's Rebuild / Render) carries `priority`, which runs it as // `umtool take … --priority` — every other heavy job waits for its render, the // editor's transcription and download lanes are held, both let go at its end. // The banner reads /api/render-mode (the state file), whoever turned it on. const PREF_KEY = "umtool:render-priority"; /** Whether this browser gives its renders the machine. Off when storage cannot be read. */ export function renderPriorityPref(): boolean { try { return localStorage.getItem(PREF_KEY) === "on"; } catch { return false; } } function setRenderPriorityPref(on: boolean) { try { if (on) localStorage.setItem(PREF_KEY, "on"); else localStorage.removeItem(PREF_KEY); } catch { /* a private window: the toggle lasts this page only */ } } type RenderModeView = { held: boolean; what: string | null; since: string | null; until: string | null; lanesHeld: string[]; lanesSkipped: string[]; lanesError: string | null; reminder: string; }; export default function RenderModeBanner() { const [ready, setReady] = useState(false); const [on, setOn] = useState(false); const [mode, setMode] = useState(null); // Read storage after hydration: reading it during render would differ from the server's. useEffect(() => { setOn(renderPriorityPref()); setReady(true); }, []); useEffect(() => { let alive = true; const look = () => fetch("/api/render-mode", { cache: "no-store" }) .then((r) => (r.ok ? r.json() : null)) .then((j: RenderModeView | null) => alive && setMode(j)) .catch(() => {}); void look(); const t = setInterval(look, 4000); return () => { alive = false; clearInterval(t); }; }, []); return (
{mode?.held ? (

Render mode:{" "} {mode.lanesHeld.length ? `${mode.lanesHeld.join(" and ")} lane${mode.lanesHeld.length > 1 ? "s" : ""} held` : "the machine held"} for {mode.what} {mode.lanesError ? ({mode.lanesError}) : null}. {capitalize(mode.reminder)}.

) : null}
); } function capitalize(s: string) { return s ? s[0].toUpperCase() + s.slice(1) : s; }