From 928983960145fcb3ee0a9ac0ec25a736930bae3f Mon Sep 17 00:00:00 2001 From: adityachandelgit <> Date: Sun, 13 Apr 2025 16:31:36 -0600 Subject: [PATCH] Initialize entityOptions based on runtime entity type (Library or Shelf) --- .../book-browser/book-browser.component.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts index 35eb0e141..747fd947d 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts @@ -138,10 +138,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { map(({entityType}) => entityType) ); - this.entity$.subscribe(entity => { - this.entity = entity; - this.entityOptions = this.libraryShelfMenuService.initializeLibraryMenuItems(entity); - this.setSelectedSortFromEntity(entity); + this.entity$?.subscribe((entity) => { + if (!entity) { + this.entityOptions = []; + return; + } + if (this.isLibrary(entity)) { + this.entityOptions = this.libraryShelfMenuService.initializeLibraryMenuItems(entity); + } else { + this.entityOptions = this.libraryShelfMenuService.initializeShelfMenuItems(entity); + } }); } @@ -153,6 +159,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }); } + private isLibrary(entity: Library | Shelf): entity is Library { + return (entity as Library).paths !== undefined; + } + toggleTableGrid() { this.gridOrTable = this.gridOrTable === 'grid' ? 'table' : 'grid'; } @@ -183,7 +193,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { if (entityType == EntityType.LIBRARY) { return this.fetchLibrary(entityId); } else if (EntityType.SHELF) { - this.libraryShelfMenuService.initializeLibraryMenuItems(this.entity); return this.fetchShelf(entityId); } return of(null);