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 => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {computed, inject, Injectable, signal} from '@angular/core';
|
||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||
import {lastValueFrom} from 'rxjs';
|
||||
import {lastValueFrom, Observable} from 'rxjs';
|
||||
import {injectInfiniteQuery, injectQuery, QueryClient} from '@tanstack/angular-query-experimental';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {AuthService} from '../../../shared/service/auth.service';
|
||||
@@ -143,6 +143,12 @@ export class AppBooksApiService {
|
||||
this.booksQuery.fetchNextPage();
|
||||
}
|
||||
|
||||
/** Fetch all book IDs matching the current filters (no pagination). */
|
||||
fetchAllBookIds(): Observable<number[]> {
|
||||
const params = this.buildFilterParams();
|
||||
return this.http.get<number[]>(`${this.booksUrl}/ids`, {params});
|
||||
}
|
||||
|
||||
/** Invalidate the books query to force a refresh from the server. */
|
||||
invalidate(): void {
|
||||
void this.queryClient.invalidateQueries({queryKey: ['app-books']});
|
||||
@@ -150,15 +156,20 @@ export class AppBooksApiService {
|
||||
}
|
||||
|
||||
private buildParams(page: number): HttpParams {
|
||||
const filters = this._filters();
|
||||
const sort = this._sort();
|
||||
const search = this._search();
|
||||
|
||||
let params = new HttpParams()
|
||||
return this.buildFilterParams()
|
||||
.set('page', page.toString())
|
||||
.set('size', PAGE_SIZE.toString())
|
||||
.set('sort', sort.field)
|
||||
.set('dir', sort.dir);
|
||||
}
|
||||
|
||||
private buildFilterParams(): HttpParams {
|
||||
const filters = this._filters();
|
||||
const search = this._search();
|
||||
|
||||
let params = new HttpParams();
|
||||
|
||||
if (search) params = params.set('search', search);
|
||||
if (filters.libraryId) params = params.set('libraryId', filters.libraryId.toString());
|
||||
|
||||
Reference in New Issue
Block a user