Files
msgapp/src/app/boards/[id]/page.tsx

49 lines
1.9 KiB
TypeScript
Raw Normal View History

import { PostList } from "@/app/components/PostList";
2025-10-24 21:24:51 +09:00
import { HeroBanner } from "@/app/components/HeroBanner";
2025-11-01 23:16:22 +09:00
import { BoardToolbar } from "@/app/components/BoardToolbar";
2025-10-10 14:39:22 +09:00
import { headers } from "next/headers";
// Next 15: params/searchParams가 Promise가 될 수 있어 안전 언랩 처리합니다.
export default async function BoardDetail({ params, searchParams }: { params: any; searchParams: any }) {
const p = params?.then ? await params : params;
const sp = searchParams?.then ? await searchParams : searchParams;
const id = p.id as string;
const sort = (sp?.sort as "recent" | "popular" | undefined) ?? "recent";
// 보드 slug 조회 (새 글 페이지 프리셋 전달)
2025-10-10 14:39:22 +09:00
const h = await headers();
const host = h.get("host") ?? "localhost:3000";
const proto = h.get("x-forwarded-proto") ?? "http";
const base = process.env.NEXT_PUBLIC_BASE_URL || `${proto}://${host}`;
const res = await fetch(new URL("/api/boards", base).toString(), { cache: "no-store" });
const { boards } = await res.json();
2025-10-10 14:39:22 +09:00
const board = (boards || []).find((b: any) => b.id === id);
2025-10-24 21:24:51 +09:00
const siblingBoards = (boards || []).filter((b: any) => b.category?.id && b.category.id === board?.category?.id);
const categoryName = board?.category?.name ?? "";
return (
2025-10-24 21:24:51 +09:00
<div className="space-y-6">
2025-11-01 23:16:22 +09:00
{/* 상단 배너 (서브카테고리 표시) */}
2025-10-24 21:24:51 +09:00
<section>
2025-11-01 23:16:22 +09:00
<HeroBanner
subItems={siblingBoards.map((b: any) => ({ id: b.id, name: b.name, href: `/boards/${b.id}` }))}
activeSubId={id}
/>
2025-10-24 21:24:51 +09:00
</section>
2025-11-01 23:16:22 +09:00
{/* 검색/필터 툴바 + 리스트 */}
<section>
<BoardToolbar boardId={id} />
2025-10-24 21:24:51 +09:00
<div className="p-0">
2025-11-01 23:16:22 +09:00
<PostList
boardId={id}
sort={sort}
variant="board"
newPostHref={`/posts/new?boardId=${id}${board?.slug ? `&boardSlug=${board.slug}` : ""}`}
/>
2025-10-24 21:24:51 +09:00
</div>
</section>
</div>
);
}