"use client"; import { useState, useTransition } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { Button } from "yt-dlp-transcript-common/components/ui/button"; import { formatBytes } from "yt-dlp-transcript-common/lib/format"; import type { SpaceSuggestion } from "yt-dlp-transcript-common/lib/spaceSuggestions"; import { runSpaceSuggestionAction } from "../actions"; // Ops that answer a dry run at once (lib/runSpaceAction.ts SPACE_DRY_RUNNABLE; // repeated here because that module is server-only). const DRY_RUNNABLE = new Set(["compress-text", "compact-saved-videos", "drop-saved-alternate"]); type Outcome = { ok: boolean; lines: string[]; jobIds: string[]; dryRun: boolean }; export function SpaceRow({ s, diskLabel }: { s: SpaceSuggestion; diskLabel: Record }) { const router = useRouter(); const [open, setOpen] = useState(false); const [preview, setPreview] = useState(null); const [done, setDone] = useState(null); const [pending, start] = useTransition(); const canDry = !!s.actions?.length && s.actions.every((a) => DRY_RUNNABLE.has(a.op)); const label = (id: string) => diskLabel[id] ?? id; const run = (dryRun: boolean) => start(async () => { const out = await runSpaceSuggestionAction(s.key, { dryRun }); if (dryRun) setPreview(out); else { setDone(out); router.refresh(); } }); return (
  • {s.title} {s.frees ? ( <> {s.basis === "estimate" ? "~" : ""} {formatBytes(s.frees.bytes)} on {label(s.frees.disk)} ) : s.later ? ( <> later ~{formatBytes(s.later.low)}–{formatBytes(s.later.high)} on {label(s.later.disk)} ) : null}
    {s.fills && ( Fills {label(s.fills.disk)} by {formatBytes(s.fills.bytes)} {s.fills.freeAfter !== null ? ` (${formatBytes(Math.max(0, s.fills.freeAfter))} free after)` : ""} ·{" "} {s.fills.fits ? "fits" : "does not fit"} )} {s.later && Frees nothing now: {s.later.when}.} {s.basisText} Loses: {s.loss} {s.shared && ( Shared: {s.shared.files} file(s), {formatBytes(s.shared.bytes)} with another hard link, not counted )} {s.disabled && {s.disabled}}
    {s.actions?.length && !s.disabled && !done?.ok ? ( open ? null : ( ) ) : null} {s.link && ( {s.link.label} )}
    {open && !done?.ok && (
    Runs{" "} {s.actions!.map((a, i) => ( pnpm ops {a.op} --json '{JSON.stringify(a.body)}' ))} {canDry && (
    {preview && (
                      {preview.lines.join("\n")}
                    
    )}
    )}
    )} {done && (
    {done.lines.join(" · ")} {done.jobIds.map((id) => ( job ))} {done.ok && · rescan to update}
    )}
  • ); }