2026-08-07 10:44:03 +07:00
|
|
|
/**
|
|
|
|
|
* Messages page — Server Component.
|
|
|
|
|
*
|
|
|
|
|
* Reads the URL (guild/channel/tab/selected) on the server and, when a guild
|
|
|
|
|
* is already selected, fetches the first message page server-side so the
|
|
|
|
|
* initial list is server-rendered, not a client round-trip.
|
|
|
|
|
*/
|
|
|
|
|
import { getMessages, type MessagePageResult } from "@/lib/api/server";
|
|
|
|
|
import MessagesView from "./view";
|
2026-07-26 11:27:21 +07:00
|
|
|
|
2026-08-07 10:44:03 +07:00
|
|
|
export default async function MessagesPage({
|
|
|
|
|
searchParams,
|
2026-07-28 10:42:12 +07:00
|
|
|
}: {
|
2026-08-07 10:44:03 +07:00
|
|
|
searchParams: Promise<Record<string, string | string[] | undefined>>;
|
2026-07-28 10:42:12 +07:00
|
|
|
}) {
|
2026-08-07 10:44:03 +07:00
|
|
|
const sp = await searchParams;
|
|
|
|
|
const guild = typeof sp.guild === "string" ? sp.guild : "";
|
|
|
|
|
const channel = typeof sp.channel === "string" ? sp.channel : "";
|
|
|
|
|
const selected = typeof sp.selected === "string" ? sp.selected : null;
|
|
|
|
|
const tab =
|
|
|
|
|
typeof sp.tab === "string" && ["all", "images", "review"].includes(sp.tab)
|
|
|
|
|
? (sp.tab as "all" | "images" | "review")
|
|
|
|
|
: "all";
|
|
|
|
|
|
|
|
|
|
let initialPage: MessagePageResult | undefined;
|
|
|
|
|
if (guild) {
|
|
|
|
|
initialPage = await getMessages(guild, channel || undefined).catch(
|
|
|
|
|
() => undefined,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 10:05:08 +07:00
|
|
|
return (
|
2026-08-07 10:44:03 +07:00
|
|
|
<MessagesView
|
|
|
|
|
initialGuild={guild}
|
|
|
|
|
initialChannel={channel}
|
|
|
|
|
initialDetailId={selected}
|
|
|
|
|
initialTab={tab}
|
|
|
|
|
initialMessagePage={initialPage}
|
|
|
|
|
/>
|
2026-07-26 11:27:21 +07:00
|
|
|
);
|
|
|
|
|
}
|