80 lines
2.2 KiB
TypeScript
80 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 CantoInfo = {
|
|
number: number;
|
|
title: string;
|
|
totalChapters: number;
|
|
chapters: ChapterInfo[];
|
|
};
|
|
|
|
export default async function SbChapterPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ canto: string; chapter: string }>;
|
|
}) {
|
|
const { canto, chapter } = await params;
|
|
const PAGE_SIZE = 20;
|
|
|
|
const meta = await getBookMeta("sb");
|
|
if (!meta) notFound();
|
|
|
|
const cantos = (meta as unknown as { cantos: CantoInfo[] }).cantos;
|
|
const cantoInfo = cantos.find((c) => c.number === parseInt(canto));
|
|
if (!cantoInfo) notFound();
|
|
|
|
const chapterInfo = cantoInfo.chapters.find(
|
|
(ch) => ch.number === parseInt(chapter),
|
|
);
|
|
if (!chapterInfo) notFound();
|
|
|
|
const [verseIndex, firstPage] = await Promise.all([
|
|
getChapterVerseIndex("sb", canto, parseInt(chapter)),
|
|
getChapterVerses("sb", canto, parseInt(chapter), 1, PAGE_SIZE),
|
|
]);
|
|
if (verseIndex.length === 0) notFound();
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<PageHeader sticky wide>
|
|
<Link
|
|
href={`/books/sb/${canto}`}
|
|
className="text-sm text-muted-foreground hover:text-foreground"
|
|
>
|
|
← Canto {cantoInfo.number}: {cantoInfo.title}
|
|
</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="sb"
|
|
division={canto}
|
|
chapter={parseInt(chapter)}
|
|
limit={PAGE_SIZE}
|
|
showBengali={false}
|
|
verseIndex={verseIndex.map((v) => ({
|
|
verse: v.verse,
|
|
verseEnd: v.verseEnd ?? undefined,
|
|
reference: v.reference,
|
|
}))}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|