From 2e20f54513aeb9238022887b74bdba61804b1795 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 29 Jun 2026 14:10:55 +0000 Subject: [PATCH] Add admin UI to review and promote created lessons --- src/app/admin/AdminCreations.tsx | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/app/admin/AdminCreations.tsx diff --git a/src/app/admin/AdminCreations.tsx b/src/app/admin/AdminCreations.tsx new file mode 100644 index 0000000..6b84c92 --- /dev/null +++ b/src/app/admin/AdminCreations.tsx @@ -0,0 +1,71 @@ +"use client"; +import { useState } from "react"; +import { useRouter } from "next/navigation"; + +interface Row { + id: number; + subject: string; + level: string; + status: string; + slug: string; + emoji: string; +} + +export default function AdminCreations({ review, ready }: { review: Row[]; ready: Row[] }) { + const router = useRouter(); + const [busy, setBusy] = useState(null); + + async function act(id: number, action: "approve" | "block" | "promote") { + setBusy(id); + try { + await fetch(`/api/admin/create/${id}`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ action }), + }); + router.refresh(); + } finally { + setBusy(null); + } + } + + if (review.length === 0 && ready.length === 0) { + return

No creations awaiting review.

; + } + + return ( +
+ {review.length > 0 && ( + <> + Awaiting review +
+ {review.map((r) => ( +
+ {r.emoji} {r.subject} ยท {r.level} + + + + +
+ ))} +
+ + )} + {ready.length > 0 && ( + <> + Ready โ€” promote to everyone? +
+ {ready.map((r) => ( +
+ {r.emoji} {r.subject} ยท {r.level} + +
+ ))} +
+ + )} +
+ ); +} + +const mini: React.CSSProperties = { minHeight: 34, padding: "6px 12px", fontSize: "0.85rem", boxShadow: "none" };