"use client"; import { useState, useTransition } from "react"; import { Hash, Loader2, CheckCircle2 } from "lucide-react"; import { previewReparseCodes, reparseCodes, type ReparseCodesPreview } from "@/app/actions/maintenance"; type State = | { kind: "idle" } | { kind: "scanning" } | { kind: "preview"; data: ReparseCodesPreview } | { kind: "running" } | { kind: "done"; filled: number; updated: number; skipped: number }; export function ReparseCodesButton() { const [state, setState] = useState({ kind: "idle" }); const [pending, start] = useTransition(); const scan = () => { setState({ kind: "scanning" }); start(async () => { const data = await previewReparseCodes(); setState({ kind: "preview", data }); }); }; const run = (force: boolean) => { if (state.kind !== "preview") return; const count = force ? state.data.missing + state.data.changed : state.data.missing; const verb = force ? "Re-parse all (overwrite manual edits)" : "Fill missing only"; if (!confirm(`${verb} for ${count} cover${count === 1 ? "" : "s"}? Files won't move into new letter buckets until you also run Re-organize, and thumbnail filenames won't update until Regenerate Thumbnails runs.`)) return; setState({ kind: "running" }); start(async () => { const r = await reparseCodes({ force }); setState({ kind: "done", ...r }); }); }; return (
Re-parse Codes From Filenames
Re-run the JAV-code parser against every cover's stored filename. Useful after a parser change (added z-suffix or alphanumeric prefix support, etc.) so old rows pick up the new behaviour. Pair with Re-organize + Regenerate Thumbnails to also move files and rename thumbs.
{state.kind === "preview" && (
{state.data.missing} missing {" · "} {state.data.changed} would change {" · "}of {state.data.total} top-level covers
{state.data.sampleChanges.length > 0 && (
Preview {state.data.sampleChanges.length} sample change{state.data.sampleChanges.length === 1 ? "" : "s"}
{state.data.sampleChanges.map((c) => (
{c.oldCode} {c.newCode} {c.filename}
))}
)}
)} {state.kind === "done" && (
Filled {state.filled} · updated {state.updated} · skipped {state.skipped}
)}
{state.kind === "idle" && ( )} {(state.kind === "scanning" || state.kind === "running") && ( {state.kind === "scanning" ? "Scanning…" : "Updating…"} )} {state.kind === "preview" && ( <> {state.data.missing > 0 && ( )} {state.data.changed > 0 && ( )} )} {state.kind === "done" && ( )}
); }