fix(filter): update filter options to use CountedOption for read statuses and file types (#448)
* fix(filter): update filter options to use CountedOption for read statuses and file types * fix(specification): validate file types and read statuses, throwing APIException for invalid values
This commit is contained in:
@@ -318,7 +318,11 @@
|
||||
></app-book-table>
|
||||
}
|
||||
@if (currentViewMode === 'grid') {
|
||||
<virtual-scroller class="virtual-scroller" #scroll [items]="books" [bufferAmount]="16" (vsEnd)="onScrollEnd()">
|
||||
<virtual-scroller class="virtual-scroller" #scroll
|
||||
[items]="books"
|
||||
[bufferAmount]="16"
|
||||
[compareItems]="compareBookItems"
|
||||
(vsEnd)="onScrollEnd()">
|
||||
<div
|
||||
class="grid"
|
||||
#container
|
||||
@@ -326,7 +330,7 @@
|
||||
@for (book of scroll.viewPortItems; let i = $index; track book.id) {
|
||||
<div
|
||||
class="virtual-scroller-item"
|
||||
[ngStyle]="{width: currentCardSize.width + 'px', height: getCardHeight(book) + 'px'}">
|
||||
[ngStyle]="{width: currentCardSize.width + 'px', height: currentCardSize.height + 'px'}">
|
||||
<app-book-card
|
||||
[index]="bookIndexById().get(book.id) ?? i"
|
||||
[book]="book"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {AfterViewInit, Component, HostListener, computed, effect, inject, OnDestroy, OnInit, signal, untracked, ViewChild} from '@angular/core';
|
||||
import {AfterViewInit, ChangeDetectionStrategy, Component, HostListener, computed, effect, inject, OnDestroy, OnInit, signal, untracked, ViewChild} from '@angular/core';
|
||||
import {toObservable, toSignal} from '@angular/core/rxjs-interop';
|
||||
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
|
||||
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
||||
@@ -72,6 +72,7 @@ export enum EntityType {
|
||||
standalone: true,
|
||||
templateUrl: './book-browser.component.html',
|
||||
styleUrls: ['./book-browser.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [
|
||||
Button, VirtualScrollerModule, BookCardComponent, Menu, InputText, FormsModule,
|
||||
BookTableComponent, BookFilterComponent, Tooltip, NgClass, NgStyle, Popover,
|
||||
@@ -226,8 +227,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
case 'mood': scopeFilters.mood = strValues; break;
|
||||
case 'narrator': scopeFilters.narrator = strValues; break;
|
||||
case 'language': scopeFilters.language = strValues; break;
|
||||
case 'readStatus': scopeFilters.status = strValues[0]; break;
|
||||
case 'bookType': scopeFilters.fileType = strValues[0]; break;
|
||||
case 'readStatus': scopeFilters.status = strValues; break;
|
||||
case 'bookType': scopeFilters.fileType = strValues; break;
|
||||
}
|
||||
}
|
||||
const mode = this.selectedFilterMode();
|
||||
@@ -256,34 +257,24 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return Number.isNaN(entityId) ? entityType : `${entityType}:${entityId}`;
|
||||
});
|
||||
|
||||
private readonly pipelineInputs = computed(() => ({
|
||||
books: this.appBooksApi.books(),
|
||||
entity: this.entityInfo(),
|
||||
search: this.debouncedSearchTerm(),
|
||||
filter: this.selectedFilter(),
|
||||
filterMode: this.selectedFilterMode(),
|
||||
collapsed: this.seriesCollapsed(),
|
||||
forceExpand: this.forceExpandSeries(),
|
||||
sort: this.sortCriteria(),
|
||||
}));
|
||||
private readonly pipelineInputs = computed(() => this.appBooksApi.books());
|
||||
|
||||
private readonly renderBooksEffect = effect((onCleanup) => {
|
||||
const contextKey = this.booksContextKey();
|
||||
this.pipelineInputs();
|
||||
const books = this.pipelineInputs();
|
||||
|
||||
const shouldRefreshInPlace = untracked(() => this.hasRenderedBooks()) && contextKey === this.lastBooksContextKey;
|
||||
this.lastBooksContextKey = contextKey;
|
||||
|
||||
if (shouldRefreshInPlace) {
|
||||
const requestId = this.booksRenderState.begin('refresh');
|
||||
this.booksRenderState.commit(requestId, this.appBooksApi.books());
|
||||
this.booksRenderState.update(books);
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = this.booksRenderState.begin('reset');
|
||||
|
||||
const timeout = globalThis.setTimeout(() => {
|
||||
this.booksRenderState.commit(requestId, this.appBooksApi.books());
|
||||
this.booksRenderState.commit(requestId, books);
|
||||
});
|
||||
|
||||
onCleanup(() => {
|
||||
@@ -302,6 +293,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
return map;
|
||||
});
|
||||
readonly compareBookItems = (a: Book, b: Book): boolean => a?.id === b?.id;
|
||||
protected resetFilterSubject = new Subject<void>();
|
||||
|
||||
readonly skeletonSlots = Array.from({length: 24}, (_, index) => index);
|
||||
|
||||
+2
-8
@@ -152,15 +152,9 @@ export class BookFilterService {
|
||||
bookCount: lang.count,
|
||||
}));
|
||||
case 'readStatus':
|
||||
return (options.readStatuses ?? []).map((status: string) => ({
|
||||
value: {id: status, name: status},
|
||||
bookCount: 0,
|
||||
}));
|
||||
return this.countedToFilters(options.readStatuses);
|
||||
case 'bookType':
|
||||
return (options.fileTypes ?? []).map((ft: string) => ({
|
||||
value: {id: ft, name: ft},
|
||||
bookCount: 0,
|
||||
}));
|
||||
return this.countedToFilters(options.fileTypes);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ export class DeferredRenderState<T> {
|
||||
return this.activeRequestId;
|
||||
}
|
||||
|
||||
/** Direct update without refresh animation used for in-place data swaps. */
|
||||
update(value: T): void {
|
||||
this._value.set(value);
|
||||
this._isRefreshing.set(false);
|
||||
}
|
||||
|
||||
commit(requestId: number, value: T): boolean {
|
||||
if (requestId !== this.activeRequestId) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user