"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { announceManifestChanged } from "./timelineApi"; // --------------------------------------------------------------------------- // ADD POSTS to a cut of posts (lane/ui-simplify, 5 Nov): the channel's // archived posts the cut does not play yet, as post items -- `umtool posts reel` // in the app (POST /api/report/add-posts, postReel.mjs postsReel). Preview // lists what it would add; Add writes them in one undoable write. // --------------------------------------------------------------------------- type Row = { id: string; date: string | null; handle: string | null; text: string; media: number }; type Answer = { ok?: boolean; error?: string; added?: number; selected?: number; already?: number; dryRun?: boolean; entries?: Row[] }; export default function AddPosts({ project, channels: known }: { project: string; channels: string[] }) { const router = useRouter(); const [open, setOpen] = useState(false); const [channel, setChannel] = useState(known[0] ?? ""); const [own, setOwn] = useState(true); const [since, setSince] = useState(""); const [until, setUntil] = useState(""); const [busy, setBusy] = useState(false); const [plan, setPlan] = useState(null); const [done, setDone] = useState(null); const go = async (dryRun: boolean) => { setBusy(true); const r = await fetch("/api/report/add-posts", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, channels: [channel.trim()], own, since: since || null, until: until || null, dryRun }), }); const j = (await r.json().catch(() => ({ error: `HTTP ${r.status}` }))) as Answer; setBusy(false); if (!r.ok) j.error ??= `HTTP ${r.status}`; if (dryRun) { setPlan(j); setDone(null); } else { setDone(j); setPlan(null); if (r.ok) { announceManifestChanged(project); router.refresh(); } } }; const input = "rounded-[3px] border border-seam-2 bg-ground px-1.5 py-[3px] text-[12px] text-text outline-none focus:border-signal"; return ( <> {open && (

Add posts

the archive's posts this cut does not play yet
{[plan, done].map((a, k) => a ? (
{a.error ? (

{a.error}

) : ( <>

{k === 0 ? "would add" : "added"} {a.added} post item{a.added === 1 ? "" : "s"} ({a.selected} selected, {a.already} already in the cut)

    {(a.entries ?? []).map((e) => (
  1. {e.date} {e.id} {e.text} {e.media > 0 && +{e.media}}
  2. ))}
)}
) : null, )}
)} ); }