"use client"; import { useState, useTransition } from "react"; import { useRouter } from "next/navigation"; import type { ConnectedArchive } from "yt-dlp-transcript-common/lib/remoteArchives"; import type { ArchiveProbe } from "yt-dlp-transcript-common/lib/remoteArchives-server"; import { connectArchiveAction, removeArchiveAction } from "../actions"; // CONNECTED ARCHIVES (demo epic D1): the published archives this machine reads // as sources. Type an origin → Read it (its corpus.json: title, channels, // videos, nothing saved) → Connect. Each row's Remove drops it; the one // TRANSCRIPT_SITE_URL names is listed and cannot be removed here. const nf = new Intl.NumberFormat("en-US"); export function ConnectArchive({ archives }: { archives: ConnectedArchive[] }) { const router = useRouter(); const [pending, start] = useTransition(); const [origin, setOrigin] = useState(""); const [probe, setProbe] = useState(null); const [error, setError] = useState(null); const [said, setSaid] = useState(null); const read = () => start(async () => { setError(null); setSaid(null); setProbe(null); const r = await connectArchiveAction(origin, true); if (r.ok) setProbe(r.result.probe); else setError(r.error); }); const connect = () => start(async () => { setError(null); const r = await connectArchiveAction(probe?.origin ?? origin, false); if (!r.ok) return setError(r.error); setSaid(r.result.already ? `${r.result.archive.title} was connected already.` : `Connected ${r.result.archive.title}.`); setProbe(null); setOrigin(""); router.refresh(); }); const remove = (id: string) => start(async () => { setError(null); const r = await removeArchiveAction(id); if (!r.ok) setError(r.error); else router.refresh(); }); return (
{archives.length > 0 ? (
    {archives.map((a) => (
  • {a.title}
    {a.origin} {a.fromEnv ? " · from TRANSCRIPT_SITE_URL" : ` · connected ${a.addedAt.slice(0, 10)}`}
    {!a.fromEnv && ( )}
  • ))}
) : (

No archive connected.

)}
{ e.preventDefault(); if (probe && probe.origin) connect(); else read(); }} > { setOrigin(e.target.value); setProbe(null); }} className="w-80 rounded-md border border-border bg-background px-2 py-1 text-sm" /> {probe && ( )}
{probe && (
{probe.title}
{nf.format(probe.totals.channels)} channel{probe.totals.channels === 1 ? "" : "s"} · {nf.format(probe.totals.videos)} videos {probe.generatedAt ? ` · built ${probe.generatedAt.slice(0, 10)}` : ""} {probe.spec !== null ? ` · corpus spec ${probe.spec}` : ""}
    {probe.channels.slice(0, 40).map((c) => (
  • {c.name} {c.videoCount !== null ? {nf.format(c.videoCount)} : null}
  • ))} {probe.channels.length > 40 &&
  • …and {probe.channels.length - 40} more
  • }
)} {said &&

{said}

} {error && (

{error}

)}
); }