From 4cb82d2ba7b3d36337f2db75f9e9c9cc3c815812 Mon Sep 17 00:00:00 2001 From: adityachandelgit <> Date: Thu, 15 May 2025 20:53:14 -0600 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=9CUnassigned=E2=80=9D=20shelf=20vi?= =?UTF-8?q?ew=20for=20books=20not=20in=20any=20shelf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- booklore-ui/src/app/app.routes.ts | 1 + .../book-browser/book-browser.component.html | 9 +++-- .../book-browser/book-browser.component.ts | 40 ++++++++++++++----- .../src/app/book/service/shelf.service.ts | 8 ++++ .../layout-menu/app.menu.component.ts | 40 ++++++++++++------- .../layout-menu/app.menuitem.component.html | 6 +-- 6 files changed, 74 insertions(+), 30 deletions(-) diff --git a/booklore-ui/src/app/app.routes.ts b/booklore-ui/src/app/app.routes.ts index ebd7a4bea..d3b927873 100644 --- a/booklore-ui/src/app/app.routes.ts +++ b/booklore-ui/src/app/app.routes.ts @@ -38,6 +38,7 @@ export const routes: Routes = [ {path: 'settings', component: SettingsComponent, canActivate: [AuthGuard]}, {path: 'library/:libraryId/books', component: BookBrowserComponent, canActivate: [AuthGuard]}, {path: 'shelf/:shelfId/books', component: BookBrowserComponent, canActivate: [AuthGuard]}, + {path: 'unshelved-books', component: BookBrowserComponent, canActivate: [AuthGuard]}, {path: 'book/:bookId', component: BookMetadataCenterComponent, canActivate: [AuthGuard]} ] }, diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html index 2998e7a54..be700d3f8 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html @@ -3,14 +3,17 @@
-

+

{{ entityType }}: {{ (entity$ | async)?.name }}

All Books

+

+ Unshelved Books +

-
+
@@ -126,7 +129,7 @@
this.fetchBooksByEntity(entityId, entityType)), - ); - this.entity$ = routeEntityInfo$.pipe( switchMap(({entityId, entityType}) => this.fetchEntity(entityId, entityType)) ); @@ -255,6 +256,23 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { ); } + private fetchUnshelvedBooks(): Observable { + return this.bookService.bookState$.pipe( + map(bookState => { + const unshelvedBooks = (bookState.books || []).filter(book => + !book.shelves || book.shelves.length === 0 + ); + return { + ...bookState, + books: unshelvedBooks + }; + }), + map(bookState => this.processBookState(bookState)), + switchMap(bookState => this.headerFilter(bookState)), + switchMap(bookState => this.sideBarFilter(bookState)) + ); + } + private sideBarFilter(bookState: BookState): Observable { return this.selectedFilter.pipe( map((activeFilters: Record | null) => { @@ -287,7 +305,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }); }); - return { ...bookState, books: filteredBooks }; + return {...bookState, books: filteredBooks}; }) ); } @@ -397,6 +415,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { applySortOption(sortOption: SortOption): void { if (this.entityType === EntityType.ALL_BOOKS) { this.bookState$ = this.fetchAllBooks(); + } else if (this.entityType === EntityType.UNSHELVED) { + this.bookState$ = this.fetchUnshelvedBooks(); } else { const routeParam$ = this.getEntityInfoFromRoute(); this.bookState$ = routeParam$.pipe( diff --git a/booklore-ui/src/app/book/service/shelf.service.ts b/booklore-ui/src/app/book/service/shelf.service.ts index fd7a5d857..44af83b42 100644 --- a/booklore-ui/src/app/book/service/shelf.service.ts +++ b/booklore-ui/src/app/book/service/shelf.service.ts @@ -106,4 +106,12 @@ export class ShelfService { ) ); } + + getUnshelvedBookCount(): Observable { + return this.bookService.bookState$.pipe( + map(state => + (state.books || []).filter(book => !book.shelves || book.shelves.length === 0).length + ) + ); + } } diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts b/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts index ab1304c3b..af01df7d5 100644 --- a/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts +++ b/booklore-ui/src/app/layout/component/layout-menu/app.menu.component.ts @@ -57,20 +57,32 @@ export class AppMenuComponent implements OnInit { ); this.shelfMenu$ = this.shelfService.shelfState$.pipe( - map((state) => [ - { - label: 'Shelves', - separator: false, - items: state.shelves?.map((shelf) => ({ - menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf), - label: shelf.name, - type: 'Shelf', - icon: 'pi pi-' + shelf.icon, - routerLink: [`/shelf/${shelf.id}/books`], - bookCount$: this.shelfService.getBookCount(shelf.id ?? 0), - })) || [], - }, - ]) + map((state) => { + const shelves = state.shelves?.map((shelf) => ({ + menu: this.libraryShelfMenuService.initializeShelfMenuItems(shelf), + label: shelf.name, + type: 'Shelf', + icon: 'pi pi-' + shelf.icon, + routerLink: [`/shelf/${shelf.id}/books`], + bookCount$: this.shelfService.getBookCount(shelf.id ?? 0), + })) || []; + + const unshelvedItem = { + label: 'Unshelved', + type: 'Shelf', + icon: 'pi pi-inbox', + routerLink: ['/unshelved-books'], + bookCount$: this.shelfService.getUnshelvedBookCount?.() ?? of(0), + }; + + return [ + { + label: 'Shelves', + separator: false, + items: [unshelvedItem, ...shelves], + }, + ]; + }) ); this.homeMenu$ = this.bookService.bookState$.pipe( diff --git a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html index 62681cf8a..6dc591f9d 100644 --- a/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html +++ b/booklore-ui/src/app/layout/component/layout-menu/app.menuitem.component.html @@ -30,7 +30,7 @@ - +

{{ (item.bookCount$ | async)?.toString() || '0' }}

-
+