From c7cfe266d47bbbecb16751a8756dfad411106a1a Mon Sep 17 00:00:00 2001 From: ACX <8075870+acx10@users.noreply.github.com> Date: Thu, 1 Jan 2026 13:48:39 -0700 Subject: [PATCH] Fix: Deselect items when they are removed from current view in book browser (#2093) Co-authored-by: acx10 --- .../book-browser/book-browser.component.ts | 38 +++++++++++-------- .../shelf-assigner.component.ts | 6 +-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts index afbff6113..6dcf0a8ea 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts @@ -256,15 +256,15 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.userService.userState$.pipe(filter(u => !!u?.user && u.loaded)) .subscribe(userState => { - this.metadataMenuItems = this.bookMenuService.getMetadataMenuItems( - () => this.autoFetchMetadata(), - () => this.fetchMetadata(), - () => this.bulkEditMetadata(), - () => this.multiBookEditMetadata(), - () => this.regenerateCoversForSelected(), - userState.user - ); - }); + this.metadataMenuItems = this.bookMenuService.getMetadataMenuItems( + () => this.autoFetchMetadata(), + () => this.fetchMetadata(), + () => this.bulkEditMetadata(), + () => this.multiBookEditMetadata(), + () => this.regenerateCoversForSelected(), + userState.user + ); + }); this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); @@ -476,18 +476,18 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { if (selected) { if (book.seriesBooks) { //it is a series - this.selectedBooks = new Set([...this.selectedBooks, ...book.seriesBooks.map(book=>book.id)]); + this.selectedBooks = new Set([...this.selectedBooks, ...book.seriesBooks.map(book => book.id)]); } else { - this.selectedBooks.add(book.id); + this.selectedBooks.add(book.id); } } else { if (book.seriesBooks) { //it is a series - book.seriesBooks.forEach(book =>{ + book.seriesBooks.forEach(book => { this.selectedBooks.delete(book.id); }); } else { - this.selectedBooks.delete(book.id); + this.selectedBooks.delete(book.id); } } } @@ -557,7 +557,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.selectedBooks.clear(); }); }, - reject: () => {} + reject: () => { + } }); } @@ -656,6 +657,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { openShelfAssigner(): void { this.dynamicDialogRef = this.dialogHelperService.openShelfAssignerDialog(null, this.selectedBooks); + if (this.dynamicDialogRef) { + this.dynamicDialogRef.onClose.subscribe(result => { + if (result.assigned) { + this.selectedBooks.clear(); + } + }); + } } lockUnlockMetadata(): void { @@ -709,7 +717,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { life: 3000 }); } - }); + }); } }); } diff --git a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts index ed293dd6e..643a4af37 100644 --- a/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts +++ b/booklore-ui/src/app/features/book/components/shelf-assigner/shelf-assigner.component.ts @@ -74,11 +74,11 @@ export class ShelfAssignerComponent implements OnInit { .subscribe({ next: () => { this.messageService.add({severity: 'info', summary: 'Success', detail: 'Book shelves updated'}); - this.dynamicDialogRef.close(); + this.dynamicDialogRef.close({assigned: true}); }, error: () => { this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update book shelves'}); - this.dynamicDialogRef.close(); + this.dynamicDialogRef.close({assigned: false}); } }); } @@ -104,7 +104,7 @@ export class ShelfAssignerComponent implements OnInit { } closeDialog(): void { - this.dynamicDialogRef.close(); + this.dynamicDialogRef.close({assigned: false}); } isShelfSelected(shelf: Shelf): boolean {