Skip to content

Commit

Permalink
Handle missing chapter 1 for content items (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoore1 authored Jan 28, 2025
1 parent bd4f2f3 commit 36623bc
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/routes/contents/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { page } from '$app/stores';
import BottomNavigationBar from '$lib/components/BottomNavigationBar.svelte';
import Navbar from '$lib/components/Navbar.svelte';
import { loadCatalog } from '$lib/data/catalogData';
import config from '$lib/data/config';
import {
contentsFontSize,
Expand Down Expand Up @@ -57,7 +58,8 @@
//reference linkType
case 'reference':
contentsStack.pushItem($page.data.menu.id);
await navigateToText(getReference(item));
const contentsRef = await getReference(item);
await navigateToText(contentsRef);
break;
case 'screen':
//goes to another contents page
Expand Down Expand Up @@ -90,7 +92,7 @@
}
}
function getReference(item) {
async function getReference(item) {
let docSet = $refs.docSet;
let collection = docSet.split('_')[1];
let book;
Expand All @@ -111,11 +113,10 @@
'_' +
collection;
}
switch (reference.length) {
case 1:
book = reference[0];
chapter = '1';
chapter = await firstChapter(book, docSet);
break;
case 2:
book = reference[0];
Expand Down Expand Up @@ -165,6 +166,19 @@
goto(getRoute(`/contents/${menuId}`));
}
}
async function firstChapter(book, docset) {
let first = '1';
if (docset === currentDocSet) {
first = Object.keys(books.find((x) => x.bookCode === book).versesByChapters)[0];
} else {
let docSetCatalog = await loadCatalog(docset);
let docSetBooks = docSetCatalog.documents;
first = Object.keys(docSetBooks.find((x) => x.bookCode === book).versesByChapters)[0];
}
return first;
}
$: books = $refs.catalog.documents;
$: currentDocSet = $refs.docSet;
$: showBackButton = $contentsStack.length > 0;
const bottomNavBarEnabled = config?.bottomNavBarItems && config?.bottomNavBarItems.length > 0;
const barType = 'contents';
Expand Down

0 comments on commit 36623bc

Please sign in to comment.