From 92d1334f25f8d517cd05c664997ed3ceca01a456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Sz=C3=BCcs?= <127139797+balazs-szucs@users.noreply.github.com> Date: Mon, 2 Feb 2026 18:38:31 +0100 Subject: [PATCH] Refactor confirmation dialogs to standardize button labels and styles across components (#2562) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Balázs Szücs --- .../book-browser/book-browser.component.html | 4 +- .../book-browser/book-browser.component.ts | 29 +++++++----- .../series-page/series-page.component.html | 4 +- .../series-page/series-page.component.ts | 16 +++---- .../book/service/book-menu.service.ts | 44 ++++++++++++++++++- 5 files changed, 73 insertions(+), 24 deletions(-) diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html index 55ce08a00..b279c4ef8 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html @@ -391,7 +391,7 @@ tooltipPosition="top"> } - @if (hasBulkReadActionsItems) { + @if (hasMoreActionsItems) {
- +
} 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 138233c49..c6981c8d0 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 @@ -4,7 +4,7 @@ import {ConfirmationService, MenuItem, MessageService, PrimeTemplate} from 'prim import {PageTitleService} from '../../../../shared/service/page-title.service'; import {BookService} from '../../service/book.service'; import {debounceTime, filter, map, switchMap, takeUntil} from 'rxjs/operators'; -import {BehaviorSubject, combineLatest, finalize, Observable, of, Subject} from 'rxjs'; +import {BehaviorSubject, combineLatest, finalize, Observable, of, Subject, Subscription} from 'rxjs'; import {DynamicDialogRef} from 'primeng/dynamicdialog'; import {Library} from '../../model/library.model'; import {Shelf} from '../../model/shelf.model'; @@ -153,7 +153,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { private settingFiltersFromUrl = false; private destroy$ = new Subject(); protected metadataMenuItems: MenuItem[] | undefined; - protected bulkReadActionsMenuItems: MenuItem[] | undefined; + protected moreActionsMenuItems: MenuItem[] | undefined; private sideBarFilter = new SideBarFilter(this.selectedFilter, this.selectedFilterMode); private headerFilter = new HeaderFilter(this.searchTerm$); @@ -161,6 +161,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { selectedSort => this.onManualSortChange(selectedSort) ); + private bookStateSubscription: Subscription | undefined; + @ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent; @ViewChild(BookFilterComponent, {static: false}) @@ -262,8 +264,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { return this.metadataMenuItems!.length > 0; } - get hasBulkReadActionsItems(): boolean { - return this.bulkReadActionsMenuItems!.length > 0; + get hasMoreActionsItems(): boolean { + return this.moreActionsMenuItems!.length > 0; } ngOnInit(): void { @@ -375,7 +377,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { ); }); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } private setupQueryParamSubscription(): void { @@ -501,19 +503,19 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { onCheckboxClicked(event: CheckboxClickEvent): void { this.bookSelectionService.handleCheckboxClick(event); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } handleBookSelect(book: Book, selected: boolean): void { this.bookSelectionService.handleBookSelection(book, selected); this.isDrawerVisible = this.bookSelectionService.hasSelection(); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } onSelectedBooksChange(selectedBookIds: Set): void { this.bookSelectionService.setSelectedBooks(selectedBookIds); this.isDrawerVisible = this.bookSelectionService.hasSelection(); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } selectAllBooks(): void { @@ -521,7 +523,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { if (this.bookTableComponent) { this.bookTableComponent.selectAllBooks(); } - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } deselectAllBooks(): void { @@ -530,7 +532,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { if (this.bookTableComponent) { this.bookTableComponent.clearSelectedBooks(); } - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } confirmDeleteBooks(): void { @@ -585,9 +587,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy { ); } - this.bookState$ + if (this.bookStateSubscription) { + this.bookStateSubscription.unsubscribe(); + } + + this.bookStateSubscription = this.bookState$ .pipe( filter(state => state.loaded && !state.error), + takeUntil(this.destroy$), map(state => state.books || []) ) .subscribe(books => { diff --git a/booklore-ui/src/app/features/book/components/series-page/series-page.component.html b/booklore-ui/src/app/features/book/components/series-page/series-page.component.html index 3072bf083..d3ed85f85 100644 --- a/booklore-ui/src/app/features/book/components/series-page/series-page.component.html +++ b/booklore-ui/src/app/features/book/components/series-page/series-page.component.html @@ -173,7 +173,7 @@ tooltipPosition="top"> } - @if (hasBulkReadActionsItems) { + @if (hasMoreActionsItems) {
- +
} diff --git a/booklore-ui/src/app/features/book/components/series-page/series-page.component.ts b/booklore-ui/src/app/features/book/components/series-page/series-page.component.ts index c819ab867..f3a042617 100644 --- a/booklore-ui/src/app/features/book/components/series-page/series-page.component.ts +++ b/booklore-ui/src/app/features/book/components/series-page/series-page.component.ts @@ -94,7 +94,7 @@ export class SeriesPageComponent implements OnDestroy { // Menu items protected metadataMenuItems: MenuItem[] | undefined; - protected bulkReadActionsMenuItems: MenuItem[] | undefined; + protected moreActionsMenuItems: MenuItem[] | undefined; seriesParam$: Observable = this.route.paramMap.pipe( map((params) => params.get("seriesName") || ""), @@ -208,7 +208,7 @@ export class SeriesPageComponent implements OnDestroy { () => this.generateCustomCoversForSelected(), userState.user ); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); }); } @@ -351,12 +351,12 @@ export class SeriesPageComponent implements OnDestroy { this.handleBookSelection(book, !isUnselectingRange); } } - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } handleBookSelect(book: Book, selected: boolean): void { this.handleBookSelection(book, selected); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } selectAllBooks(): void { @@ -364,12 +364,12 @@ export class SeriesPageComponent implements OnDestroy { for (const book of this.currentBooks) { this.selectedBooks.add(book.id); } - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } deselectAllBooks(): void { this.selectedBooks.clear(); - this.bulkReadActionsMenuItems = this.bookMenuService.getBulkReadActionsMenu(this.selectedBooks, this.user()); + this.moreActionsMenuItems = this.bookMenuService.getMoreActionsMenu(this.selectedBooks, this.user()); } confirmDeleteBooks(): void { @@ -525,7 +525,7 @@ export class SeriesPageComponent implements OnDestroy { return (this.metadataMenuItems?.length ?? 0) > 0; } - get hasBulkReadActionsItems(): boolean { - return (this.bulkReadActionsMenuItems?.length ?? 0) > 0; + get hasMoreActionsItems(): boolean { + return (this.moreActionsMenuItems?.length ?? 0) > 0; } } diff --git a/booklore-ui/src/app/features/book/service/book-menu.service.ts b/booklore-ui/src/app/features/book/service/book-menu.service.ts index ad5322f6a..ef2ef567d 100644 --- a/booklore-ui/src/app/features/book/service/book-menu.service.ts +++ b/booklore-ui/src/app/features/book/service/book-menu.service.ts @@ -77,7 +77,7 @@ export class BookMenuService { return items; } - getBulkReadActionsMenu(selectedBooks: Set, user: User | null): MenuItem[] { + getMoreActionsMenu(selectedBooks: Set, user: User | null): MenuItem[] { const count = selectedBooks.size; const permissions = user?.permissions; const items: MenuItem[] = []; @@ -134,6 +134,48 @@ export class BookMenuService { }); } + // Shelf Actions + if (permissions?.canManageLibrary || permissions?.admin) { // Assuming these permissions cover shelf management for books + items.push({ + label: 'Remove from all shelves', + icon: 'pi pi-bookmark-fill', // Or bookmark-slash + command: () => { + this.confirmationService.confirm({ + message: `Are you sure you want to remove ${count} book(s) from ALL their shelves?`, + header: 'Confirm Unshelve', + icon: 'pi pi-exclamation-triangle', + acceptLabel: 'Yes', + rejectLabel: 'No', + accept: () => { + const loader = this.loadingService.show(`Removing ${count} book(s) from shelves...`); + const books = this.bookService.getBooksByIdsFromState(Array.from(selectedBooks)); + const allShelfIds = new Set(); + books.forEach(b => b.shelves?.forEach(s => { + if (s.id) allShelfIds.add(s.id); + })); + + if (allShelfIds.size === 0) { + this.loadingService.hide(loader); + this.messageService.add({ severity: 'info', summary: 'Info', detail: 'Selected books are not on any shelves.' }); + return; + } + + this.bookService.updateBookShelves(selectedBooks, new Set(), allShelfIds) + .pipe(finalize(() => this.loadingService.hide(loader))) + .subscribe({ + next: () => { + this.messageService.add({severity: 'success', summary: 'Success', detail: 'Books removed from all shelves'}); + }, + error: () => { + this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to update books shelves'}); + } + }); + } + }); + } + }); + } + if (permissions?.canBulkResetBookloreReadProgress) { items.push({ label: 'Reset Booklore Progress',