Files
spsays-training/app/books/cc/[lila]/[chapter]/page.tsx
T
2026-04-14 19:12:11 +05:30

81 lines
2.2 KiB
TypeScript

import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import { notFound } from "next/navigation";
import { getBookMeta, getChapterVerses, getChapterVerseIndex } from "@/lib/api";
import { ChapterViewer } from "@/app/books/chapter-viewer";
type ChapterInfo = {
number: number;
title: string;
totalVerses: number;
};
type LilaInfo = {
key: string;
name: string;
totalChapters: number;
totalVerses: number;
chapters: ChapterInfo[];
};
export default async function CcChapterPage({
params,
}: {
params: Promise<{ lila: string; chapter: string }>;
}) {
const { lila, chapter } = await params;
const PAGE_SIZE = 20;
const meta = await getBookMeta("cc");
if (!meta) notFound();
const lilas = meta.lilas as LilaInfo[] | undefined;
const lilaInfo = lilas?.find((l) => l.key === lila);
if (!lilaInfo) notFound();
const chapterInfo = lilaInfo.chapters.find(
(ch) => ch.number === parseInt(chapter),
);
if (!chapterInfo) notFound();
const [verseIndex, firstPage] = await Promise.all([
getChapterVerseIndex("cc", lila, parseInt(chapter)),
getChapterVerses("cc", lila, parseInt(chapter), 1, PAGE_SIZE),
]);
if (verseIndex.length === 0) notFound();
return (
<div className="min-h-screen bg-background">
<PageHeader sticky wide>
<Link
href={`/books/cc/${lila}`}
className="text-sm text-muted-foreground hover:text-foreground"
>
&larr; {lilaInfo.name}
</Link>
<h1 className="mt-2 text-2xl font-bold text-foreground">
Chapter {chapter}: {chapterInfo.title}
</h1>
</PageHeader>
<div className="w-full md:max-w-5xl mx-auto flex">
<ChapterViewer
initialVerses={firstPage.verses}
hasMore={firstPage.hasMore}
totalPages={firstPage.totalPages}
book="cc"
division={lila}
chapter={parseInt(chapter)}
limit={PAGE_SIZE}
showBengali={true}
verseIndex={verseIndex.map((v) => ({
verse: v.verse,
verseEnd: v.verseEnd ?? undefined,
reference: v.reference,
}))}
/>
</div>
</div>
);
}