Files
jiang13-bbs/frontend/app/post/[id]/edit/page.tsx
freefire b9ba8cb8c9 feat: 类型帖互动、积分经济与发帖体验
补齐问答采纳/重开、投票匿名与有票禁编、悬赏过期退回、抽奖回帖开奖,并接入积分账本与发帖附件可见性。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 03:17:07 +08:00

75 lines
2.3 KiB
TypeScript

import { cookies } from "next/headers";
import { notFound, redirect } from "next/navigation";
import Link from "next/link";
import { ChevronRight } from "lucide-react";
import { authCookieHeader } from "@/lib/cookies";
import { getMeCached } from "@/lib/serverData";
import { fetchPostDetail } from "@/lib/api";
import { canModerateBoard } from "@/lib/roles";
import EditPostClient from "./EditPostClient";
interface PageProps {
params: Promise<{ id: string }>;
}
export default async function EditPostPage({ params }: PageProps) {
const { id } = await params;
const cookie = authCookieHeader(await cookies());
const me = await getMeCached(cookie || undefined);
if (!me.user) {
redirect(`/login?redirect=${encodeURIComponent(`/post/${id}/edit`)}`);
}
let post: Awaited<ReturnType<typeof fetchPostDetail>>["post"];
try {
({ post } = await fetchPostDetail(id, cookie));
} catch {
notFound();
}
const allowed =
me.user.id === post.user.id ||
canModerateBoard(me.user, post.board_id);
if (!allowed) {
redirect(`/post/${id}`);
}
return (
<div
data-compose-viewport
className="j13-compose-page w-full max-w-6xl mx-auto"
>
<nav className="meta mb-4 flex items-center gap-1.5 flex-wrap text-[13px] shrink-0">
<Link href="/" className="hover:text-[var(--accent)] transition-colors">
首页
</Link>
<ChevronRight size={13} />
<Link
href={`/post/${post.id}`}
className="hover:text-[var(--accent)] transition-colors truncate max-w-[12rem]"
>
帖子详情
</Link>
<ChevronRight size={13} />
<span style={{ color: "var(--ink-2)" }}>编辑</span>
</nav>
<EditPostClient
postId={post.id}
initialTitle={post.title}
initialContent={post.content}
initialTags={post.tags || ""}
initialPostType={post.post_type}
initialContentAccess={post.content_access}
initialAccessPoints={post.access_points}
initialTypeMeta={post.type_meta}
initialAttachments={post.attachments || []}
canEditPollOptions={post.poll?.can_edit_options !== false}
boardName={post.board?.name || "未知板块"}
boardId={post.board_id}
boardColorIndex={post.board?.color_index ?? 0}
/>
</div>
);
}