feat(shelf): add shelf filtering options and integrate into book processing (#2268)

* feat(shelf): add shelf filtering options and integrate into book processing

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* fix(book-rule-evaluator): normalize array values to lowercase for rule comparisons

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* feat(filter): enhance library and shelf filtering logic for 'or' and 'and' modes

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

* feat(shelf): implement support for multiple shelf IDs in book retrieval and filtering

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs
2026-01-15 19:58:30 -07:00
committed by GitHub
parent 869bea9ca5
commit 775887b55f
13 changed files with 545 additions and 28 deletions
@@ -28,6 +28,8 @@ export interface Filter<T extends FilterValue = FilterValue> {
}
export type FilterType =
| 'library'
| 'shelf'
| 'author'
| 'category'
| 'series'
@@ -205,6 +207,8 @@ export class BookFilterComponent implements OnInit, OnDestroy {
private _selectedFilterMode: BookFilterMode = 'and';
expandedPanels: number[] = [0];
readonly filterLabels: Record<FilterType, string> = {
library: 'Library',
shelf: 'Shelf',
author: 'Author',
category: 'Genre',
series: 'Series',
@@ -249,6 +253,14 @@ export class BookFilterComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.filterStreams = {
library: this.getFilterStream(
(book) => (book.libraryId ? [{id: book.libraryId, name: book.libraryName}] : []),
'id', 'name'
),
shelf: this.getFilterStream(
(book) => (book.shelves ? book.shelves.map(s => ({id: s.id, name: s.name})) : []),
'id', 'name'
),
author: this.getFilterStream(
(book: Book) => Array.isArray(book.metadata?.authors) ? book.metadata.authors.map(name => ({id: name, name})) : [],
'id', 'name'
@@ -105,6 +105,14 @@ export class SideBarFilter implements BookFilter {
return bookYear ? filterValues.some(val => val == bookYear || val == bookYear.toString()) : false;
case 'fileSize':
return filterValues.some(range => isFileSizeInRange(book.fileSizeKb, range));
case 'library':
return mode === 'or'
? filterValues.some(val => val == book.libraryId)
: filterValues.every(val => val == book.libraryId);
case 'shelf':
return mode === 'or'
? filterValues.some(val => book.shelves?.some(s => s.id == val))
: filterValues.every(val => book.shelves?.some(s => s.id == val));
case 'shelfStatus':
const shelved = book.shelves && book.shelves.length > 0 ? 'shelved' : 'unshelved';
return filterValues.includes(shelved);
@@ -96,6 +96,10 @@ export class ShelfService {
return this.shelfStateSubject.value.shelves?.find(s => s.id === id);
}
getShelvesFromState(): Shelf[] {
return this.shelfStateSubject.value.shelves ?? [];
}
getBookCount(shelfId: number): Observable<number> {
return this.bookService.bookState$.pipe(
map(state =>