Skip to content

Commit

Permalink
Check that the book and chapter exist in the current book collection …
Browse files Browse the repository at this point in the history
…before going to reference.
  • Loading branch information
davidmoore1 committed Dec 3, 2024
1 parent f944077 commit 330914a
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,38 +103,51 @@
return displayString;
}
function checkReference(book, chapter) {
let value = false;
const books = $refs.catalog.documents;
const bookInCatalog = books.find((d) => d.bookCode === book);
const chaptersInBook = bookInCatalog?.versesByChapters ?? [];
const chapterInBook = Object.keys(chaptersInBook).find((x) => x === chapter.toString());
if (bookInCatalog && chapterInBook) {
value = true;
}
return value;
}
function goToDailyReference(item, ref, index) {
// Only go to reference if in an active plan
if (inUse) {
let currentBookCollectionId = $refs.collection;
const [collection, book, fromChapter, toChapter, verseRanges] =
getReferenceFromString(ref);
const [fromVerse, toVerse, separator] = verseRanges[0];
let destinationVerse = fromVerse === -1 ? 1 : fromVerse;
getNextPlanReference($page.data.planData.id, item, index).then(
([nextReference, nextIndex]) => {
$plan = {
planId: $page.data.planData.id,
planDay: item.day,
planEntry: index,
planBookId: book,
planChapter: toChapter,
planFromVerse: fromVerse,
planToVerse: toVerse,
planReference: ref,
planNextReference: nextReference,
planNextReferenceIndex: nextIndex,
completed: false
};
refs.set({
docSet: currentBookCollectionId,
book: book,
chapter: toChapter.toString(),
verse: destinationVerse.toString()
});
goto(`${base}/text`);
}
);
if (checkReference(book, toChapter)) {
let destinationVerse = fromVerse === -1 ? 1 : fromVerse;
getNextPlanReference($page.data.planData.id, item, index).then(
([nextReference, nextIndex]) => {
$plan = {
planId: $page.data.planData.id,
planDay: item.day,
planEntry: index,
planBookId: book,
planChapter: toChapter,
planFromVerse: fromVerse,
planToVerse: toVerse,
planReference: ref,
planNextReference: nextReference,
planNextReferenceIndex: nextIndex,
completed: false
};
refs.set({
docSet: currentBookCollectionId,
book: book,
chapter: toChapter.toString(),
verse: destinationVerse.toString()
});
goto(`${base}/text`);
}
);
}
}
}
function handleBackNavigation(event) {
Expand Down

0 comments on commit 330914a

Please sign in to comment.