"use client"; import { useEffect, useState } from "react"; import { Loader2 } from "lucide-react"; import { apiAdminListAnnouncements, type Announcement } from "@/lib/api"; import AnnouncementComposeClient from "../../AnnouncementComposeClient"; /** 无详情 API:从管理列表按 id 拉取后进入编辑器 */ export default function AnnouncementEditLoader({ id }: { id: number }) { const [item, setItem] = useState(null); const [error, setError] = useState(""); const [loading, setLoading] = useState(true); useEffect(() => { let alive = true; setLoading(true); apiAdminListAnnouncements() .then((res) => { if (!alive) return; const found = res.announcements.find((a) => a.id === id) ?? null; if (!found) { setError("公告不存在或已删除"); setItem(null); } else { setItem(found); setError(""); } }) .catch((e) => { if (!alive) return; setError(e instanceof Error ? e.message : "加载失败"); }) .finally(() => { if (alive) setLoading(false); }); return () => { alive = false; }; }, [id]); if (loading) { return (
加载公告…
); } if (error || !item) { return

{error || "公告不存在"}

; } return ; }