Initialize entityOptions based on runtime entity type (Library or Shelf)

This commit is contained in:
adityachandelgit
2025-04-13 16:32:12 -06:00
committed by Aditya Chandel
parent 9e6640f27f
commit 9289839601
@@ -138,10 +138,16 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
map(({entityType}) => entityType) map(({entityType}) => entityType)
); );
this.entity$.subscribe(entity => { this.entity$?.subscribe((entity) => {
this.entity = entity; if (!entity) {
this.entityOptions = this.libraryShelfMenuService.initializeLibraryMenuItems(entity); this.entityOptions = [];
this.setSelectedSortFromEntity(entity); 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() { toggleTableGrid() {
this.gridOrTable = this.gridOrTable === 'grid' ? 'table' : 'grid'; this.gridOrTable = this.gridOrTable === 'grid' ? 'table' : 'grid';
} }
@@ -183,7 +193,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
if (entityType == EntityType.LIBRARY) { if (entityType == EntityType.LIBRARY) {
return this.fetchLibrary(entityId); return this.fetchLibrary(entityId);
} else if (EntityType.SHELF) { } else if (EntityType.SHELF) {
this.libraryShelfMenuService.initializeLibraryMenuItems(this.entity);
return this.fetchShelf(entityId); return this.fetchShelf(entityId);
} }
return of(null); return of(null);