Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split things up #604

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -1,15 +1,58 @@
import clsx from 'clsx';
import React, { useRef, useState } from 'react';

Check failure on line 2 in src/components/organisms/passageNavigation.tsx

View workflow job for this annotation

GitHub Actions / lint

'useRef' is defined but never used. Allowed unused vars must match /_/u

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 All @@ -33,56 +76,30 @@
</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
Loading