"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { ChevronRight, PenSquare } from "lucide-react"; import { apiCreatePost, apiMe, fetchBoards, type Board } from "@/lib/api"; import { toast } from "@/lib/toast"; export default function ComposePage() { const router = useRouter(); const [boards, setBoards] = useState([]); const [boardId, setBoardId] = useState(0); const [title, setTitle] = useState(""); const [content, setContent] = useState(""); const [tags, setTags] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); useEffect(() => { apiMe() .then((res) => { if (!res.user) { router.push("/login?redirect=/compose"); return; } fetchBoards().then((data) => { setBoards(data.boards); if (data.boards.length > 0) setBoardId(data.boards[0].id); }); }) .catch(() => router.push("/login?redirect=/compose")); }, [router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); try { const res = await apiCreatePost({ board_id: boardId, title, content, tags, post_type: "normal", }); if (res.post) { // 普通用户发帖进入待审核队列:跳转详情页(作者可见)并提示 if (res.post.status === "pending") { toast("已提交,等待审核通过后公开", "ok"); } router.push(`/post/${res.post.id}`); } else { setError(res.error || "发帖失败"); } } finally { setLoading(false); } }; return (

发布新帖

清晰的标题和内容,更容易获得回应

{error &&
{error}
}
setTitle(e.target.value)} required maxLength={256} placeholder="一句话说清楚你要讨论什么" className="field" />
setTags(e.target.value)} placeholder="Go, PostgreSQL, 架构" className="field" />