import Link from "next/link"; import { notFound } from "next/navigation"; import AppShell from "@/components/shell/AppShell"; import { ARTICLES_KEY } from "@/lib/articles/key.mjs"; import { articleHref, articlesHref } from "@/lib/hrefs"; import { badgeVariants } from "@/components/ui/badge"; import { isReportId } from "yt-dlp-transcript-common/lib/report/schema"; import { readCompareSide, type CompareSide } from "@/lib/articles/compare"; export const dynamic = "force-dynamic"; // TWO ITERATIONS OF AN ARTICLE SIDE BY SIDE (release 27 S8): // /articles//compare?a=&b=. Each side's report — sections, and the // findings in them, a finding the other side does not have marked — the ops // its revision applied and refused, its failed checks; and, when both have a // project, the two cuts. Server-rendered, zero client JS. const num = (v: string | undefined) => { const n = Number(v); return Number.isInteger(n) && n > 0 ? n : null; }; function Side({ side, other, both }: { side: CompareSide; other: CompareSide; both: boolean }) { const otherFindings = new Set(other.sections.flatMap((s) => s.findings.map((f) => f.text))); const otherTitles = new Set(other.sections.map((s) => s.title)); const otherCut = new Set((other.cut?.entries ?? []).map((e) => `${e.type}:${e.id}:${e.narration ?? e.quote ?? ""}`)); return (
{/* The side's head: which iteration, by whom, at what spend -- a Panel, not a page header (the page has one, the shell's). */}

{side.label}

{side.kind} {side.model} {side.status} ${side.usd.toFixed(2)}

{side.parent !== null ? `of i${side.parent}` : "first sweep"} {side.copyOf !== null ? ` · copy of i${side.copyOf}` : ""} {side.reportFrom !== null && side.reportFrom !== side.n ? ` · report of i${side.reportFrom}` : ""} {side.minutes !== null ? ` · ${side.minutes.toFixed(1)} min` : ""}

{(side.feedback ?? side.question) &&

{side.feedback ? `“${side.feedback}”` : side.question}

}
ops: {side.applied.length} applied · {side.refused.length} refused
{side.applied.length + side.refused.length > 0 && (
    {side.applied.map((o) => (
  • ✓ {o.index} {o.op} {o.detail}
  • ))} {side.refused.map((o) => (
  • ✕ {o.index} {o.op} {o.detail} {o.why &&
    {o.why}
    }
  • ))}
)}
{side.failedChecks.length > 0 && (
failed checks
    {side.failedChecks.map((c, i) => (
  • {c.name} {c.detail ? `: ${c.detail}` : ""}
  • ))}
)} {side.title ? (

{side.title}

{side.summary &&

{side.summary}

} {side.sections.map((s, i) => (

{s.title} {!otherTitles.has(s.title) && only here}

    {s.findings.map((f, j) => { const changed = !otherFindings.has(f.text); return (
  • {f.text} {f.cites > 0 && [{f.cites}]}
  • ); })}
))}
) : (

no report

)} {both && side.cut && (
cut{side.cut.title ? `: ${side.cut.title}` : ""}
    {side.cut.entries.map((e, i) => { const changed = !otherCut.has(`${e.type}:${e.id}:${e.narration ?? e.quote ?? ""}`); return (
  1. {e.type === "card" ? ( <> ▌ {e.heading} {e.narration &&
    {e.narration}
    } ) : ( <> {e.id} {e.span} {" "} {e.quote && `“${e.quote}”`} )}
  2. ); })}
)}
); } export default async function ComparePage({ params, searchParams, }: { params: Promise<{ report: string }>; searchParams: Promise<{ a?: string; b?: string }>; }) { const { report } = await params; const sp = await searchParams; if (!isReportId(report)) notFound(); const a = num(sp.a); const b = num(sp.b); const [left, right] = a && b ? await Promise.all([readCompareSide(report, a), readCompareSide(report, b)]) : [null, null]; const iterations = articleHref({ site: ARTICLES_KEY, id: report }, { tab: "iterations" }); const header = ( ); if (!left || !right) { return (
{header}

{!a || !b ? "name two iterations: ?a=&b=" : `no iteration ${!left ? `i${a}` : `i${b}`}`} —{" "} the iterations

); } const both = !!left.cut && !!right.cut; return (
{header}
); }