Fix ZXDB pagination counters and navigation
Implement URL-driven pagination and correct total counts across ZXDB: - Root /zxdb: SSR reads ?page; client syncs to SSR; Prev/Next as Links. - Sub-index pages (genres, languages, machinetypes): parse ?page on server; use SSR props in clients; Prev/Next via Links. - Labels browse (/zxdb/labels): dynamic SSR, reads ?q & ?page; typed count(*); client syncs to SSR; Prev/Next preserve q. - Label detail (/zxdb/labels/[id]): tab-aware Prev/Next Links; counters from server. - Repo: replace raw counts with typed Drizzle count(*) for reliable totals. Signed-off-by: Junie <Junie@lucy.xalior.com>
This commit is contained in:
@@ -3,17 +3,21 @@ import { getLabelById, getLabelAuthoredEntries, getLabelPublishedEntries } from
|
||||
|
||||
export const metadata = { title: "ZXDB Label" };
|
||||
|
||||
export const revalidate = 3600;
|
||||
// Depends on searchParams (?page=, ?tab=). Force dynamic so each request renders correctly.
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
export default async function Page({ params, searchParams }: { params: Promise<{ id: string }>;
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }> }) {
|
||||
const [{ id }, sp] = await Promise.all([params, searchParams]);
|
||||
const numericId = Number(id);
|
||||
const page = Math.max(1, Number(Array.isArray(sp.page) ? sp.page[0] : sp.page) || 1);
|
||||
const tab = (Array.isArray(sp.tab) ? sp.tab[0] : sp.tab) as "authored" | "published" | undefined;
|
||||
const [label, authored, published] = await Promise.all([
|
||||
getLabelById(numericId),
|
||||
getLabelAuthoredEntries(numericId, { page: 1, pageSize: 20 }),
|
||||
getLabelPublishedEntries(numericId, { page: 1, pageSize: 20 }),
|
||||
getLabelAuthoredEntries(numericId, { page, pageSize: 20 }),
|
||||
getLabelPublishedEntries(numericId, { page, pageSize: 20 }),
|
||||
]);
|
||||
|
||||
// Let the client component handle the "not found" simple state
|
||||
return <LabelDetailClient id={numericId} initial={{ label: label as any, authored: authored as any, published: published as any }} />;
|
||||
return <LabelDetailClient id={numericId} initial={{ label: label as any, authored: authored as any, published: published as any }} initialTab={tab} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user