"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { api } from "./api"; type Col = { slug: string; title: string; description: string; published: boolean; items: { tool: string; blurb?: string | null }[] }; export function CollectionsEditor({ initial }: { initial: Col[] }) { const r = useRouter(); const [sel, setSel] = useState(null); const [msg, setMsg] = useState(""); const blank: Col = { slug: "", title: "", description: "", published: false, items: [] }; return
{sel &&
{ e.preventDefault(); try { await api("/api/admin/collections", { method: "POST", body: JSON.stringify(sel) }); setMsg("Saved"); r.refresh(); } catch (e) { setMsg((e as Error).message); } }}>