"use client"; import { useRouter } from "next/navigation"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { newClipEntry, quoteFromCues } from "@/lib/report/clipEditorModel.mjs"; import { cn } from "@/lib/utils"; import { announceManifestChanged, refusalOf, timelineOp, type TimelineResult } from "./timelineApi"; import { parseMomentInput, parseTime as parseTimeOf } from "@/lib/report/momentLink.mjs"; // --------------------------------------------------------------------------- // ADD A CLIP, AS ONE FLOW (lane/ui-simplify, 5 Nov; the operator: "adding new // clips to a cut really sucks"). // // 1 Find the words, in the recordings the cut already draws on // (/api/report/find-moment) or across the archive // (/api/research/search); or paste a link with a time // 2 In/out on the moment's cues: click a line to start there, shift-click // to end there; nudge ±0.5 s; the quote is read from the cues // 3 Place after -- by default where the clip's date falls when the // cut is in date order, else after the row it was opened from // 4 Add the timeline's own insert -- the draft's (L3: a take is a // frozen version; "add to this take only" is retired), then the clip's // window fetched through the editor's paced fetch // (POST /api/report/fetch) -- never yt-dlp by hand // // Opened from the Cut tab, from Play at the playhead's item ("Add a clip // here"). The old one-line spec form stays as the Cut // tab's "Add by spec". // --------------------------------------------------------------------------- type Entry = { id: string; type: string; date?: string | null; video?: string | null; channel?: string | null; words?: string }; type Moment = { channel: string | null; video: string; title: string | null; date: string | null; t: number; text?: string }; type Cue = { start: number; end: number; text: string; endsSentence?: boolean }; type FetchState = { state: "idle" } | { state: "running"; msg: string } | { state: "done"; msg: string } | { state: "failed"; msg: string }; const r2 = (n: number) => Math.round(n * 100) / 100; const clock = (s: number) => { const h = Math.floor(s / 3600); const m = Math.floor((s % 3600) / 60); const sec = Math.floor(s % 60); return h ? `${h}:${String(m).padStart(2, "0")}:${String(sec).padStart(2, "0")}` : `${m}:${String(sec).padStart(2, "0")}`; }; /** `1:02:32`, `62m32s`, `3752`, `1h2m32s` → seconds; null when it is not a time (lib/report/momentLink.mjs). */ export const parseTime = parseTimeOf as (v: string | null | undefined) => number | null; /** * A pasted link or a short form → `{ video, t, channel? }` (lib/report/momentLink.mjs, home's Quick clip box's * parser too): a YouTube link (`v=`, youtu.be, /live/, /shorts/) with t= or start=, an archive's moment link, a * Rumble link, `/