From 6ec9f51e370875fd85c0f7ce5fdf7cba1cdd2e6a Mon Sep 17 00:00:00 2001 From: Chris Hubbard Date: Wed, 20 Nov 2024 14:11:16 -0500 Subject: [PATCH] Handle if htmlBooks is missing (cached data) (#730) --- src/lib/data/catalogData.ts | 2 +- src/lib/data/navigation.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/data/catalogData.ts b/src/lib/data/catalogData.ts index b4bd2cd0a..c66189d21 100644 --- a/src/lib/data/catalogData.ts +++ b/src/lib/data/catalogData.ts @@ -23,7 +23,7 @@ export interface CatalogData { }[]; tags: {}; quizzes: {}; - htmlBooks: { + htmlBooks?: { id: string; name: string; }[]; diff --git a/src/lib/data/navigation.ts b/src/lib/data/navigation.ts index a293b2a4c..15f8cbd7f 100644 --- a/src/lib/data/navigation.ts +++ b/src/lib/data/navigation.ts @@ -74,7 +74,10 @@ export class NavigationContext { this.collection = docSet.split('_')[1]; this.catalog = await this.fetchCatalog(this.docSet); this.books = this.catalog.documents.map((b) => b.bookCode); - this.allBookIds = [...this.books, ...this.catalog.htmlBooks.map((b) => b.id)]; + this.allBookIds = [ + ...this.books, + ...(this.catalog.htmlBooks ? this.catalog.htmlBooks.map((b) => b.id) : []) + ]; newBook = true; } if (book !== this.book && this.allBookIds.includes(book)) { @@ -128,7 +131,7 @@ export class NavigationContext { return; } - const htmlBook = this.catalog.htmlBooks.find((b) => b.id === this.book); + const htmlBook = this.catalog.htmlBooks?.find((b) => b.id === this.book); if (htmlBook) { this.title = htmlBook.name; this.name = htmlBook.name;