"use client"; import { useEffect, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { LitLine, LitOnly } from "@/components/ui/lit-line"; import { isoDate } from "@/lib/research/facets.mjs"; import type { CaseSection, Quote } from "@/lib/research/case-types"; import { cn } from "@/lib/utils"; // --------------------------------------------------------------------------- // One QUOTE on the board (canvas `.quote`): the words on the reader surface // (a slip: verbatim, the source's), its cite in mono under them; then on the // desk what is OURS -- the claim line, the note, the flags (speaker not // checked; drifted, missing, en-orig differs) and what the last re-verify // read. Paper is the record, ink is our work: a quote is never styled as our // claim, nor our claim as a quote. // // The claim and the note are edited in place: Enter or leaving the field // saves, Escape puts it back. The line is a lit line of the board's list; its // grip drags it. // --------------------------------------------------------------------------- const TRACK: Record = { transcript: "transcription", captions: "captions", unknown: "", post: "post" }; export const quoteLineId = (qid: string) => `q:${qid}`; function InlineField({ label, value, placeholder, onSave, field, className, max, tabbable, }: { /** In the Tab order only on the lit quote (e and n reach it from the keys). */ tabbable: boolean; label: string; value: string; placeholder: string; onSave: (v: string) => void; field: "claim" | "note"; className?: string; max: number; }) { const [v, setV] = useState(value); const ref = useRef(null); // Enter saved it already: the blur that follows (focus back to the line) does not again. const done = useRef(false); useEffect(() => setV(value), [value]); const back = () => ref.current?.closest("[data-lit-line]")?.focus({ preventScroll: true }); return ( setV(e.target.value)} onFocus={() => (done.current = false)} onBlur={() => { if (!done.current && v.trim() !== value.trim()) onSave(v); }} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); if (v.trim() !== value.trim()) onSave(v); done.current = true; back(); } else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); setV(value); done.current = true; back(); } }} className={cn( "min-w-0 rounded-[2px] border border-transparent bg-transparent px-1 py-0.5 outline-none placeholder:text-muted-2 hover:border-seam focus:border-seam-2 focus:bg-ground", className, )} /> ); } export default function QuoteSlip({ q, sections, lit, busy, onPatch, onRemove, onDragStart, onDropOn, }: { q: Quote; sections: CaseSection[]; lit: boolean; busy: boolean; onPatch: (body: Record) => void; onRemove: () => void; onDragStart: (qid: string) => void; onDropOn: (qid: string, after: boolean) => void; }) { const [over, setOver] = useState<"before" | "after" | null>(null); const c = q.cite; const v = q.verify; const where = [ c.title, c.channelName ?? c.channel, c.date ? isoDate(c.date) : "", c.kind === "post" ? "" : c.clock, c.trackId ? `${c.trackId} track` : TRACK[c.track ?? ""] ?? "", c.localOnly ? "local only" : "", ].filter(Boolean); const drifted = v?.status === "drifted"; return ( { if (!e.dataTransfer.types.includes("application/x-umtool-quote")) return; e.preventDefault(); const r = e.currentTarget.getBoundingClientRect(); setOver(e.clientY > r.top + r.height / 2 ? "after" : "before"); }} onDragLeave={() => setOver(null)} onDrop={(e) => { e.preventDefault(); const after = over === "after"; setOver(null); onDropOn(q.id, after); }} className={cn( "mb-3 grid grid-cols-[22px_minmax(0,1fr)] rounded-[3px] border border-seam bg-panel p-0 last:border-b", over === "before" && "shadow-[0_-2px_0_var(--signal)]", over === "after" && "shadow-[0_2px_0_var(--signal)]", )} >

“{q.text}”

{c.url ? ( {where.join(" · ")} ) : ( where.join(" · ") )}
Claim onPatch({ claim })} className="flex-1 text-text" />
{q.by === "agent" && ( by agent )} {q.by === "triage" && ( by triage )} {c.kind !== "post" && (q.speakerChecked ? ( Speaker checked ) : ( Speaker not checked ))} {drifted && ( Drifted )} {v?.status === "missing" && Missing} {v?.enOrig && ( en-orig differs )} note: onPatch({ note })} className="flex-1 text-text-2" /> {v?.status === "ok" && verified {v.at.slice(0, 10)}} {!v && not re-verified}
{drifted && (
Re-verified {v.at.slice(0, 10)}: the transcript at {c.clock} now reads {v.now ? `“${v.now}”` : (no words there now)} The quote above keeps the words as pinned. {v.now ? ( ) : null}
)} {v?.status === "missing" &&
{v.message ?? "The recording was not found at its cite."}
} {v?.status === "unreadable" &&
Not re-verified: {v.message}
} {v?.message && v.status === "ok" &&
{v.message}
} {v?.enOrig && (
{v.enOrig.quoted === "en" ? "Quoted from the served en track; en-orig, the words as spoken, says " : "The served en track says otherwise here; en-orig says "} “{v.enOrig.text}” {v.enOrig.quoted === "en" ? " — check the audio before using it." : ""}
)}
); }