"use client"; import StoredUrlOption from "@/components/clips/StoredUrlOption"; import Link from "next/link"; import { useEffect, useRef, useState } from "react"; import { VIDEO_STATE_LABELS, type VideoState } from "yt-dlp-transcript-common/lib/availability"; import { clock } from "@/components/ui/clock"; import { EmptyState } from "@/components/ui/empty-state"; import { ReaderPane, paperButtonVariants } from "@/components/ui/reader-pane"; import { isoDate } from "@/lib/research/facets.mjs"; import { researchMediaApi } from "@/lib/research/hrefs"; import type { FetchAnswer, LocalMedia, WindowResponse } from "@/lib/research/types"; // --------------------------------------------------------------------------- // The reader on the Research page (canvas `.paper`): the transcript around the // lit hit, on the pale surface, the hit's cue lit among dim ones; ± widens or // narrows the window; the footer's actions name what they do. // // Pin to board the cited cue to the chosen case, as a snapshot quote (R2) // Copy citation the house format: "quote" [title @ m:ss](moment link) // Play from m:ss a file umtool can play from this machine (a fetched // window, a kept source or its audio), from the cite // Fetch clip the seconds behind the cite, through the editor's // fetch-window route, as the MCP's fetch_clip asks // --------------------------------------------------------------------------- const TRACK: Record = { transcript: "transcription", captions: "captions", unknown: "text of unknown kind" }; /** The best local file for a second: a window holding it, else a whole source, else audio. */ export function playable(media: LocalMedia[], at: number): LocalMedia | null { const windows = media.filter((m) => m.kind === "window" && m.from !== undefined && m.to !== undefined && m.from <= at && at <= m.to); windows.sort((a, b) => a.to! - a.from! - (b.to! - b.from!)); return windows[0] ?? media.find((m) => m.kind === "source") ?? media.find((m) => m.kind === "audio") ?? null; } function PinButton({ onPin, pinning, board }: { onPin: () => void; pinning: boolean; board: string | null }) { return ( ); } function PinNote({ pinned }: { pinned: { text: string; href?: string; tone?: "error" } | null }) { if (!pinned) return null; return ( {pinned.text} {pinned.href && ( <> {" · "} Open board )} ); } export default function Reader({ source, win, error, loading, span, onSpan, copied, onCopy, fetchState, onFetch, fromStored = false, onFromStored, onPin, pinning, pinned, board, }: { onPin: () => void; pinning: boolean; pinned: { text: string; href?: string; tone?: "error" } | null; /** The chosen case's title, or null: a pin asks which. */ board: string | null; source: string; win: WindowResponse | null; error: string | null; loading: boolean; span: number; onSpan: (s: number) => void; copied: boolean; onCopy: () => void; fetchState: FetchAnswer | { state: "asking" } | null; onFetch: () => void; /** "Cut from the stored media URL" (release 32 R6): offered when the record stores one. */ fromStored?: boolean; onFromStored?: (v: boolean) => void; }) { const [playing, setPlaying] = useState(null); const video = useRef(null); useEffect(() => setPlaying(null), [win?.videoId, win?.at]); // The cited cue in the middle of the window, wherever the window starts. useEffect(() => { const id = requestAnimationFrame(() => { const lit = document.querySelector("[data-reader] .reader-cue[data-lit]"); const box = lit?.closest(".overflow-auto"); if (!lit || !box) return; const l = lit.getBoundingClientRect(); const b = box.getBoundingClientRect(); box.scrollTop += l.top - b.top - b.height / 2 + l.height / 2; }); return () => cancelAnimationFrame(id); }, [win?.videoId, win?.at, win?.span]); if (!win) { return ( ); } if (win.kind === "post") { return ( } fine={win.citation.text} >

{win.text}

); } const file = playable(win.media, win.at); const offset = playing?.kind === "window" ? win.at - (playing.from ?? 0) : win.at; const state = VIDEO_STATE_LABELS[win.state as VideoState] ?? win.state; const fetching = fetchState && (fetchState.state === "asking" || fetchState.state === "queued"); return ( {TRACK[win.track] ?? win.track} · {win.cueCount.toLocaleString("en-US")} cues , win.localOnly ? "local only" : null, ]} cite={win.duration > 0 ? { at: win.at, duration: win.duration } : undefined} note={win.trackLabel ? `The hit is in the ${win.trackLabel}` : undefined} cues={win.cues.map((c, i) => ({ t: c.t, text: c.text, lit: i === win.lit, id: `cue-${c.t}` }))} footer={ <> {playing && (