Skip to content

Commit

Permalink
Merge branch 'bible-ui' into list-books
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Dec 5, 2024
2 parents 54175e5 + 531eac1 commit 2ce69a7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 61 deletions.
5 changes: 0 additions & 5 deletions src/components/organisms/passageNavigation.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@

.chaptersWrapper {
width: 100%;
display: none;
}

.chaptersWrapper:global(.active) {
display: block;
float: left;
}

Expand Down
121 changes: 69 additions & 52 deletions src/components/organisms/passageNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,58 @@ import clsx from 'clsx';
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';

import Link from '~components/atoms/linkWithoutPrefetch';

import { PassageNavigationFragment } from './__generated__/passageNavigation';
import BookGrid from './bookGrid';
import BookList from './bookList';
import styles from './passageNavigation.module.scss';

type Props = {
books: Array<PassageNavigationFragment>;
};

// FIXME
const OT = [
'genesis',
'exodus',
'leviticus',
'numbers',
'deuteronomy',
'joshua',
'judges',
'ruth',
'1 samuel',
'2 samuel',
'1 kings',
'2 kings',
'1 chronicles',
'2 chronicles',
'ezra',
'nehemiah',
'esther',
'job',
'psalms',
'proverbs',
'ecclesiastes',
'song of solomon',
'isaiah',
'jeremiah',
'lamentations',
'ezekiel',
'daniel',
'hosea',
'joel',
'amos',
'obadiah',
'jonah',
'micah',
'nahum',
'habakkuk',
'zephaniah',
'haggai',
'zechariah',
'malachi',
];

export default function PassageNavigation({ books }: Props): JSX.Element {
const [selectedBook, setSelectedBook] = useState<string | number | null>(
null,
Expand Down Expand Up @@ -42,56 +85,30 @@ export default function PassageNavigation({ books }: Props): JSX.Element {
</button>
</div>

<ul className={clsx(styles.books, { grid: selectedView === 'grid' })}>
{books.map((book) => {
const chapters = book.recordings.nodes;

return (
<>
<li
key={book.id}
className={clsx(styles.book, {
active: book.id === selectedBook,
})}
>
<button
onClick={() => {
setSelectedBook(book.id);
}}
>
{selectedView === 'grid'
? book.title.replace(' ', '').substring(0, 3)
: book.title}
</button>
</li>
{book.id === selectedBook ? (
<li
className={clsx(styles.chaptersWrapper, {
active: book.id === selectedBook,
})}
>
<ul
className={clsx(styles.chapters, {
active: book.id === selectedBook,
})}
>
{chapters?.map((chapter) => {
const n = Number(chapter.title.split(' ').pop());
return (
<li key={n} className={styles.chapter}>
<Link href={chapter.canonicalPath}>{n}</Link>
</li>
);
})}
</ul>
</li>
) : (
''
)}
</>
);
})}
</ul>
{selectedView === 'list' ? (
<BookList
books={books}
selectedBook={selectedBook}
selectBook={setSelectedBook}
/>
) : (
<>
<BookGrid
books={books.filter((book) =>
OT.includes(book.title.toLocaleLowerCase()),
)}
selectedBook={selectedBook}
selectBook={setSelectedBook}
/>
<BookGrid
books={books.filter(
(book) => !OT.includes(book.title.toLocaleLowerCase()),
)}
selectedBook={selectedBook}
selectBook={setSelectedBook}
/>
</>
)}
</div>
);
}
8 changes: 4 additions & 4 deletions src/pages/[language]/bibles/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ async function transform(
): Promise<ApiBible> {
const books = Object.keys(BOOK_ID_MAP).map(
async (bookId, i): Promise<ApiBook> => {
const testiment = i < 39 ? 'OT' : 'NT';
const testament = i < 39 ? 'OT' : 'NT';
const bbChapters = await getBibleBookChapters(
bible.id,
testiment,
testament,
bookId,
);
const chapters = bbChapters.map(
Expand All @@ -55,9 +55,9 @@ async function transform(
const title = bbChapters[0].book_name;

if (!title) {
console.log({ bible, testiment, bookId, bbChapters });
console.log({ bible, testament, bookId, bbChapters });
throw new Error(
`Could not determine book title: ${bible.id} ${testiment} ${bookId}`,
`Could not determine book title: ${bible.id} ${testament} ${bookId}`,
);
}

Expand Down

0 comments on commit 2ce69a7

Please sign in to comment.