import { clock } from "@/components/ui/clock"; import { projectsHref, reviewHref } from "@/lib/hrefs"; import { cuesInWindow, readClipDetail, readManifest } from "@/lib/projects/report.mjs"; import { manifestToken } from "@/lib/report/manifest.mjs"; import { draftsView } from "@/lib/report/drafts.mjs"; import { readFieldProvenance } from "@/lib/report/draft-provenance.mjs"; import { pieceHrefOfProject } from "@/lib/pieces/article"; import { awaitingReview } from "@/lib/inbox/drafts.mjs"; import type { ProjectRef } from "@/lib/project-types"; import { BenchFrame, BenchTop } from "./bench/BenchShell"; import { MediaReview, type FieldEvidence, type FieldProvenance } from "./MediaDrafts"; import type { DraftsView } from "./drafts"; import AuditionDeck from "./review/AuditionDeck"; // `/projects//review` -- the drafts review. By default the AUDITION // DECK (release 32 R1, components/projects/review/AuditionDeck.tsx): one card // per field awaiting review, its cited span playing, keep / cut / edit / skip // as one gesture. `?view=list` is the list below, for bulk work. // // The list is a BENCH (P4b): every // drafted field of the cut, walked one at a time -- `j`/`k` light a field, // `a` approves it, `r` rejects it with its note -- the verdict bar asking // about the lit field, the reader showing the clip it is drawn over. The // Media tab draws the same list with each section's "Draft with" (one // component, components/projects/MediaDrafts.tsx). Verdicts are // /drafts.review.json; a final build refuses a drafted field not // approved on its current value (release 28, M0). const spanOf = (e: { start: number; end: number; cutStart?: number; cutEnd?: number }) => { const cut = Number.isFinite(Number(e.cutStart)) && Number.isFinite(Number(e.cutEnd)) && Number(e.cutStart) < Number(e.cutEnd); const from = cut ? Number(e.cutStart) : Number(e.start); const to = cut ? Number(e.cutEnd) : Number(e.end); return Number.isFinite(from) && Number.isFinite(to) && from < to ? { from, to } : null; }; const ymd = (d: string | null | undefined) => (d && /^\d{8}$/.test(d) ? `${d.slice(0, 4)}-${d.slice(4, 6)}-${d.slice(6, 8)}` : (d ?? null)); export default async function ReviewPage({ project, view: mode }: { project: ProjectRef; view?: string }) { // The audition deck (release 32 R1) unless `?view=list`: the same fields, one card at a time. const list = mode === "list"; const manifest = await readManifest(project.dir); const [view, provenance, token, detail] = await Promise.all([ draftsView(project.dir, manifest ?? {}) as Promise, readFieldProvenance(project.dir, manifest ?? {}) as Promise>, manifestToken(project.dir), manifest ? readClipDetail(project.dir, { manifest }) : Promise.resolve(null), ]); // Every field on the list, drafted or a narration written by hand. const counts = { approved: 0, rejected: 0, edited: 0, unreviewed: 0 }; for (const r of view.rows) counts[r.state] += 1; // The source of every clip a drafted field is drawn over: the reader's. const evidence: Record = {}; const wanted = new Set(view.rows.map((r) => r.entry).filter((e): e is string => !!e)); type Entry = { id: string; kind: string; start: number; end: number; cutStart?: number; cutEnd?: number; cite?: number | null; quote?: string | null; video?: string; channel?: string | null; sourceChannel?: string | null; sourceTitleClean?: string | null; title?: string | null; uploadDate?: string | null; date?: string | null; duration?: number | null; citeUrl?: string | null }; for (const e of ((detail?.entries ?? []) as Entry[]).filter((x) => x.kind === "clip" && wanted.has(x.id))) { const win = await cuesInWindow(project.dir, e.id, e.start - 20, e.end + 20).catch(() => null); const at = e.cite ?? e.start; const duration = e.duration ?? win?.duration ?? null; evidence[e.id] = { source: e.sourceTitleClean || e.title || e.video || e.id, byline: [e.channel, e.date ?? ymd(e.uploadDate), `transcript${duration ? ` · ${clock(duration)}` : ""}`].filter((x): x is string => !!x), cite: duration ? { at, duration } : null, quote: e.quote ?? null, url: e.citeUrl ?? null, cues: (win?.cues ?? []).map((c: { start: number; end: number; text: string }) => ({ start: c.start, end: c.end, text: c.text })), // What plays (components/clips/CitedClip.tsx): the cut's own extent when // it has one, else the clip's; the corpus's directories -- a Rumble // entry's local dir is `video`, never its siteVideo. target: spanOf(e) && e.channel && e.video ? { channel: e.channel, video: e.video, ...spanOf(e)!, project: project.id, clip: e.id } : null, speaker: e.sourceChannel ?? null, }; } // The piece this view belongs to: the article's when an article claims the project (P4a-2). const back = await pieceHrefOfProject(project.id, { tab: "media" }); // Where a misheard word is fixed: the article's Iterations tab (R2's "Fix a mishearing" form reads `heard`), // when an article claims the project. const articlePage = await pieceHrefOfProject(project.id, { tab: "iterations" }); const respell = articlePage.startsWith("/projects/") ? null : articlePage; // To review: the drafted fields awaiting a verdict (the Media tab's count, the Inbox's). const toReview = awaitingReview(view.rows, provenance).length; return ( } > {list ? ( ) : ( )} ); }