diff --git a/src/components/organisms/passageNavigation/index.tsx b/src/components/organisms/passageNavigation/index.tsx index a5fd74900..af3e488c4 100644 --- a/src/components/organisms/passageNavigation/index.tsx +++ b/src/components/organisms/passageNavigation/index.tsx @@ -21,6 +21,9 @@ export type Version = NonNullable< GetAudiobibleIndexDataQuery['collections']['nodes'] >[0]; +type Book = NonNullable[0]; +type Chapter = NonNullable[0]; + type BookId = string | number | null; type ChapterId = string | number; @@ -73,20 +76,34 @@ const OT = [ 'malachi', ]; -function findVersionAndBookId( +function getBibleData( versions: Array, chapterId: ChapterId, -): [Version, BookId] { +): [Version, Book, Chapter] { for (const version of versions) { for (const book of version.sequences.nodes || []) { - if (book.recordings.nodes?.find((r) => r.id === chapterId)) { - return [version, book.id]; + const chapter = book.recordings.nodes?.find((r) => r.id === chapterId); + if (chapter) { + return [version, book, chapter]; } } } throw Error("Couldn't find the chapter"); } +function getLabelText( + versions: Array, + chapterId: ChapterId | null, +): string { + if (chapterId) { + const [_version, _book, chapter] = getBibleData(versions, chapterId); + + return `${chapter.title}`; + } + + return `Bible`; +} + export default function PassageNavigation({ versions, chapterId, @@ -109,12 +126,9 @@ export default function PassageNavigation({ } if (selectedChapterId !== null) { - const [version, bookId] = findVersionAndBookId( - versions, - selectedChapterId, - ); + const [version, book] = getBibleData(versions, selectedChapterId); setSelectedVersion(version); - setSelectedBookId(bookId); + setSelectedBookId(book.id); } }, [selectedChapterId, chapterId, setSelectedChapterId, versions]); @@ -126,7 +140,10 @@ export default function PassageNavigation({ return (
setOpen(!open)}> - +