Open History to see the last commit
1import { notFound } from "next/navigation";
2import {
3 commentQuery,
4 sealComments,
5 sealStory,
6 storyQuery,
7} from "@/lib/queries";
8import { parseStoryId, sortComments } from "@/lib/comments";
9import { CommentsClient } from "./comments-client";
10import { ensureThreadLoaded } from "@/lib/thread-load";
11export const dynamic = "force-dynamic";
12export default async function Page({
13 searchParams,
14}: {
15 searchParams: Promise<Record<string, string | string[] | undefined>>;
16}) {
17 const params = await searchParams;
18 let id: number;
19 try {
20 id = parseStoryId(params.id);
21 } catch {
22 notFound();
23 }
24 const stories = await storyQuery(id);
25 if (!stories.length) notFound();
26 await ensureThreadLoaded(id);
27 const [comments, storyQuerySealed, commentsQuerySealed] = await Promise.all([
28 commentQuery(id),
29 sealStory(id),
30 sealComments(id),
31 ]);
32 return (
33 <CommentsClient
34 key={id}
35 initialStories={stories}
36 initialComments={sortComments(comments)}
37 queries={{ story: storyQuerySealed, comments: commentsQuerySealed }}
38 initialNow={Date.now()}
39 />
40 );
41}