fix(books): make "select all" actually select all not just the books loaded in (#533)
This commit is contained in:
@@ -848,10 +848,20 @@ export class BookBrowserComponent implements AfterViewInit {
|
||||
}
|
||||
|
||||
selectAllBooks(): void {
|
||||
this.bookSelectionService.selectAll();
|
||||
if (this.bookTableComponent) {
|
||||
this.bookTableComponent.selectAllBooks();
|
||||
}
|
||||
this.appBooksApi.fetchAllBookIds().pipe(take(1)).subscribe({
|
||||
next: (allIds) => {
|
||||
this.bookSelectionService.selectAll(allIds);
|
||||
if (this.bookTableComponent) {
|
||||
this.bookTableComponent.selectAllBooks();
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
this.bookSelectionService.selectAll();
|
||||
if (this.bookTableComponent) {
|
||||
this.bookTableComponent.selectAllBooks();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deselectAllBooks(): void {
|
||||
|
||||
@@ -76,4 +76,13 @@ describe('BookSelectionService', () => {
|
||||
expect(service.selectedBooks()).toEqual(new Set());
|
||||
expect(service.selectedCount()).toBe(0);
|
||||
});
|
||||
|
||||
it('selects all from provided book IDs when passed to selectAll', () => {
|
||||
const books = [makeBook(1), makeBook(2)];
|
||||
service.setCurrentBooks(books);
|
||||
|
||||
service.selectAll([10, 20, 30, 40, 50]);
|
||||
expect(service.selectedBooks()).toEqual(new Set([10, 20, 30, 40, 50]));
|
||||
expect(service.selectedCount()).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,7 +72,12 @@ export class BookSelectionService {
|
||||
}
|
||||
}
|
||||
|
||||
selectAll(): void {
|
||||
selectAll(allBookIds?: number[]): void {
|
||||
if (allBookIds && allBookIds.length > 0) {
|
||||
this._selectedBooks.set(new Set(allBookIds));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.currentBooks || this.currentBooks.length === 0) return;
|
||||
|
||||
this._selectedBooks.update(current => {
|
||||
|
||||
Reference in New Issue
Block a user