"use client"; import { memo } from "react"; import { CiteThread } from "@/components/ui/cite-thread"; import { LitList, type LitDetail } from "@/components/ui/lit-list"; import { LitLine, LitOnly } from "@/components/ui/lit-line"; import { isoDate } from "@/lib/research/facets.mjs"; import { cn } from "@/lib/utils"; import type { LogMarks, ResultHit, Snip } from "@/lib/research/types"; // --------------------------------------------------------------------------- // The results (canvas `.rec` / `.rs`): one group per RECORDING (mirrors // folded into it), one lit line per matching line -- its timecode, the line // with the match marked, the recording's reading state -- and the cite thread // on the lit line only. The page's one global list: j/k from anywhere. // --------------------------------------------------------------------------- const TRACK: Record = { transcript: "transcription", captions: "captions", unknown: "", post: "post" }; function Marked({ s }: { s: Snip }) { const out: React.ReactNode[] = []; let at = 0; for (const [a, b] of s.marks) { if (a > at) out.push(s.text.slice(at, a)); out.push( {s.text.slice(a, b)} , ); at = b; } if (at < s.text.length) out.push(s.text.slice(at)); return <>{out}; } export const lineId = (key: string, i: number) => `${key}|${i}`; export const parseLineId = (id: string | null): { key: string; i: number } | null => { if (!id) return null; const bar = id.lastIndexOf("|"); return bar < 0 ? null : { key: id.slice(0, bar), i: Number(id.slice(bar + 1)) }; }; function Group({ h, mark }: { h: ResultHit; mark: "read" | "skipped" | undefined }) { const state = mark ?? "unread"; return (
{h.kind === "post" ? `Post by ${h.author ?? h.channelName}` : h.title} {h.channelName} · {isoDate(h.uploadDate)} {h.mirrors?.length ? ` · ⧉ +${h.mirrors.length}` : ""} {h.localOnly ? " · local only" : ""} {[TRACK[h.track], h.state !== "available" ? h.state.replace("_", " ") : ""].filter(Boolean).join(" · ")}
{h.snippets.map((s, i) => ( {s.scope && s.t === 0 ? s.scope : h.kind === "post" ? "post" : s.clock} {state} {h.duration && !s.scope ? ( ) : null} ))} {h.matches > h.snippets.length && (
+{h.matches - h.snippets.length} more {h.matches - h.snippets.length === 1 ? "line" : "lines"} in this recording
)}
); } const MemoGroup = memo(Group); export default function Results({ hits, marks, onLight, }: { hits: ResultHit[]; marks: LogMarks; onLight: (d: LitDetail) => void; }) { return ( {hits.map((h) => ( ))} ); }