From 032485368bed1ae7c3e4ee69566eb8a2227fab25 Mon Sep 17 00:00:00 2001 From: Daniel Filat Date: Fri, 29 Dec 2023 19:48:26 +0200 Subject: [PATCH] generates static params for all study pages --- .../[bookCode]/[chapter]/loading.tsx | 15 ------------- .../[bookCode]/[chapter]/page.tsx | 22 +++++++++++++++++++ .../ChapterPicker/ChapterPicker.tsx | 12 ++++++---- .../ChapterPicker/Header_ChapterPicker.tsx | 8 +++---- 4 files changed, 34 insertions(+), 23 deletions(-) delete mode 100644 src/app/[readerMode]/[bookCode]/[chapter]/loading.tsx diff --git a/src/app/[readerMode]/[bookCode]/[chapter]/loading.tsx b/src/app/[readerMode]/[bookCode]/[chapter]/loading.tsx deleted file mode 100644 index fad1723b..00000000 --- a/src/app/[readerMode]/[bookCode]/[chapter]/loading.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { css } from 'styled-system/css' -import { center } from 'styled-system/patterns' - -const Loading = () => ( -
-

Încărcare...

-
-) - -export default Loading diff --git a/src/app/[readerMode]/[bookCode]/[chapter]/page.tsx b/src/app/[readerMode]/[bookCode]/[chapter]/page.tsx index 16579763..72159bab 100644 --- a/src/app/[readerMode]/[bookCode]/[chapter]/page.tsx +++ b/src/app/[readerMode]/[bookCode]/[chapter]/page.tsx @@ -1 +1,23 @@ +import { range } from 'ramda' + +import { + READER_MODE, + type TReaderPageParams, +} from '~/_pages/ReaderPage/ReaderPage.types' +import { getBookList } from '~/db' + +export const generateStaticParams = async (): Promise => { + const bookList = await getBookList() + + return bookList.flatMap((book) => { + const bookCode = book.book.code.toLowerCase() + + return range(1)(book.book.chapter_count + 1).map((chapter) => ({ + bookCode, + chapter: chapter.toString(), + readerMode: READER_MODE.Study, + })) + }) +} + export { ReaderPage as default } from '~/_pages' diff --git a/src/components/organisms/ReaderControls/ChapterPicker/ChapterPicker.tsx b/src/components/organisms/ReaderControls/ChapterPicker/ChapterPicker.tsx index e1e89593..682edae1 100644 --- a/src/components/organisms/ReaderControls/ChapterPicker/ChapterPicker.tsx +++ b/src/components/organisms/ReaderControls/ChapterPicker/ChapterPicker.tsx @@ -38,10 +38,10 @@ export const ChapterPicker = ({ currBook: TBook bookList: TBook[] }) => { - const [isOpen, setIsOpen] = useState(false) - const { readerMode } = useParams() + const [isOpen, setIsOpen] = useState(false) + const [tab, setTab] = useState('book') const [selectedBook, setSelectedBook] = @@ -77,7 +77,11 @@ export const ChapterPicker = ({ }, []) return ( - setIsOpen(e.open)}> + setIsOpen(open)} + onExitComplete={() => setTab('book')} + > {currBook.name} {currChapter} @@ -94,7 +98,7 @@ export const ChapterPicker = ({ })} > setSelectedBook(currBook)} + onTabsTriggerClick={() => setSelectedBook(currBook)} /> diff --git a/src/components/organisms/ReaderControls/ChapterPicker/Header_ChapterPicker.tsx b/src/components/organisms/ReaderControls/ChapterPicker/Header_ChapterPicker.tsx index 24523ded..89279fb3 100644 --- a/src/components/organisms/ReaderControls/ChapterPicker/Header_ChapterPicker.tsx +++ b/src/components/organisms/ReaderControls/ChapterPicker/Header_ChapterPicker.tsx @@ -36,9 +36,9 @@ const tabsTriggerCss = css({ }) export const Header_ChapterPicker = ({ - resetSelectedBook, + onTabsTriggerClick, }: { - resetSelectedBook: () => void + onTabsTriggerClick: () => void }) => (
Book Chapter