"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { buttonVariants } from "@/components/ui/button"; // "Re-draft the posts" (release 29 review): the social draft again, forced, // on the iteration the cut was made from — what the Social posts section // offers when `publish.videoUrl` changed after the posts were drafted (the // link is code's, fixed when they are drafted). A post you wrote or edited is // never replaced: the draft is kept as an alternative. export default function RedraftSocial({ article, n }: { article: string; n: number }) { const router = useRouter(); const [state, setState] = useState<"idle" | "busy" | "queued" | "failed">("idle"); const [error, setError] = useState(""); async function go() { setState("busy"); setError(""); const r = await fetch("/api/articles/generate", { method: "POST", body: JSON.stringify({ task: "social", article, iteration: n, force: true }), }).catch(() => null); const b = r ? await r.json().catch(() => ({})) : {}; if (!r?.ok) { setState("failed"); setError(b.error ?? "the editor did not answer"); return; } setState("queued"); router.refresh(); } return ( {state === "queued" && queued — the Social row follows it} {state === "failed" && ( {error} )} ); }