Skip to content

Commit

Permalink
generates static params for all study pages
Browse files Browse the repository at this point in the history
  • Loading branch information
land-cap committed Dec 29, 2023
1 parent 2e51d48 commit 0324853
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
15 changes: 0 additions & 15 deletions src/app/[readerMode]/[bookCode]/[chapter]/loading.tsx

This file was deleted.

22 changes: 22 additions & 0 deletions src/app/[readerMode]/[bookCode]/[chapter]/page.tsx
Original file line number Diff line number Diff line change
@@ -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<TReaderPageParams[]> => {
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'
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export const ChapterPicker = ({
currBook: TBook
bookList: TBook[]
}) => {
const [isOpen, setIsOpen] = useState(false)

const { readerMode } = useParams<TReaderPageParams>()

const [isOpen, setIsOpen] = useState(false)

const [tab, setTab] = useState<string | null>('book')

const [selectedBook, setSelectedBook] =
Expand Down Expand Up @@ -77,7 +77,11 @@ export const ChapterPicker = ({
}, [])

return (
<Dialog.Root open={isOpen} onOpenChange={(e) => setIsOpen(e.open)}>
<Dialog.Root
open={isOpen}
onOpenChange={({ open }) => setIsOpen(open)}
onExitComplete={() => setTab('book')}
>
<Trigger_ChapterPicker>
{currBook.name} {currChapter}
</Trigger_ChapterPicker>
Expand All @@ -94,7 +98,7 @@ export const ChapterPicker = ({
})}
>
<Header_ChapterPicker
resetSelectedBook={() => setSelectedBook(currBook)}
onTabsTriggerClick={() => setSelectedBook(currBook)}
/>
<Tabs.Content value="book" className={tabsContentCss}>
<BookList_ChapterPicker>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const tabsTriggerCss = css({
})

export const Header_ChapterPicker = ({
resetSelectedBook,
onTabsTriggerClick,
}: {
resetSelectedBook: () => void
onTabsTriggerClick: () => void
}) => (
<div className={css({ gridColumn: 'content' })}>
<div
Expand All @@ -47,14 +47,14 @@ export const Header_ChapterPicker = ({
<Tabs.List className={css({ h: 'full' })}>
<Tabs.Trigger
value="book"
onClick={resetSelectedBook}
onClick={onTabsTriggerClick}
className={tabsTriggerCss}
>
Book
</Tabs.Trigger>
<Tabs.Trigger
value="chapter"
onClick={resetSelectedBook}
onClick={onTabsTriggerClick}
className={tabsTriggerCss}
>
Chapter
Expand Down

0 comments on commit 0324853

Please sign in to comment.