): any {
+ return filter.value.id ?? filter.value;
+ }
+
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
diff --git a/booklore-ui/src/app/book/components/book-browser/filters/HeaderFilter.ts b/booklore-ui/src/app/book/components/book-browser/filters/HeaderFilter.ts
index 2b55b604b..6de686043 100644
--- a/booklore-ui/src/app/book/components/book-browser/filters/HeaderFilter.ts
+++ b/booklore-ui/src/app/book/components/book-browser/filters/HeaderFilter.ts
@@ -1,7 +1,7 @@
import {BookFilter} from './BookFilter';
import {BookState} from '../../../model/state/book-state.model';
import {Observable} from 'rxjs';
-import {map} from 'rxjs/operators';
+import {map, debounceTime, distinctUntilChanged} from 'rxjs/operators';
export class HeaderFilter implements BookFilter {
@@ -13,6 +13,8 @@ export class HeaderFilter implements BookFilter {
str.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
return this.searchTerm$.pipe(
+ debounceTime(500),
+ distinctUntilChanged(),
map(term => {
const normalizedTerm = normalize(term || '');
if (normalizedTerm && normalizedTerm.trim() !== '') {
@@ -20,10 +22,17 @@ export class HeaderFilter implements BookFilter {
const title = book.metadata?.title || '';
const series = book.metadata?.seriesName || '';
const authors = book.metadata?.authors || [];
+ const categories = book.metadata?.categories || [];
+ const isbn = book.metadata?.isbn10 || '';
+ const isbn13 = book.metadata?.isbn13 || '';
+
const matchesTitle = normalize(title).includes(normalizedTerm);
const matchesSeries = normalize(series).includes(normalizedTerm);
const matchesAuthor = authors.some(author => normalize(author).includes(normalizedTerm));
- return matchesTitle || matchesSeries || matchesAuthor;
+ const matchesCategory = categories.some(category => normalize(category).includes(normalizedTerm));
+ const matchesIsbn = normalize(isbn).includes(normalizedTerm) || normalize(isbn13).includes(normalizedTerm);
+
+ return matchesTitle || matchesSeries || matchesAuthor || matchesCategory || matchesIsbn;
}) || null;
return {...bookState, books: filteredBooks};
}
diff --git a/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html b/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html
index fdc536f04..06efa88c0 100644
--- a/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html
+++ b/booklore-ui/src/app/book/components/book-searcher/book-searcher.component.html
@@ -7,7 +7,7 @@
pInputText
[(ngModel)]="searchQuery"
(input)="onSearchInputChange()"
- placeholder="Search books by title or author..."
+ placeholder="Title, Author, Series, Genre, or ISBN..."
class="w-full pr-10"
/>
@if (searchQuery) {
@@ -22,29 +22,6 @@
}
-
-
@if (books.length > 0 || searchQuery) {
();
+ #searchSubject = new BehaviorSubject('');
#subscription!: Subscription;
private bookService = inject(BookService);
private router = inject(Router);
protected urlHelper = inject(UrlHelperService);
-
- isSearchDropdownOpen = false;
-
- toggleSearchInputDropdown() {
- this.isSearchDropdownOpen = !this.isSearchDropdownOpen;
- }
-
- closeSearchDropdown() {
- this.isSearchDropdownOpen = false;
- }
+ private headerFilter = new HeaderFilter(this.#searchSubject.asObservable());
ngOnInit(): void {
this.initializeSearch();
}
initializeSearch(): void {
- this.#subscription = this.#searchSubject.pipe(
- debounceTime(350),
- distinctUntilChanged(),
- switchMap((query) => {
- const result = this.bookService.searchBooks(query);
- return of(result);
- }),
+ this.#subscription = this.bookService.bookState$.pipe(
+ switchMap(bookState => this.headerFilter.filter(bookState)),
catchError((error) => {
console.error('Error while searching books:', error);
- return of([]);
+ return of({books: [], loaded: true, error: null});
})
).subscribe({
- next: (result: Book[]) => this.books = result,
+ next: (filteredState) => {
+ this.books = this.searchQuery.trim() ? (filteredState.books || []) : [];
+ },
error: (error) => console.error('Subscription error:', error)
});
}
diff --git a/booklore-ui/src/app/book/service/book.service.ts b/booklore-ui/src/app/book/service/book.service.ts
index 8a1dcef3f..9c7e3ede7 100644
--- a/booklore-ui/src/app/book/service/book.service.ts
+++ b/booklore-ui/src/app/book/service/book.service.ts
@@ -191,21 +191,6 @@ export class BookService {
this.updateLastReadTime(book.id);
}
- searchBooks(query: string): Book[] {
- if (query.length < 2) {
- return [];
- }
- const normalize = (str: string): string => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
- const normalizedQuery = normalize(query);
- const state = this.bookStateSubject.value;
- return (state.books || []).filter(book => {
- const title = book.metadata?.title;
- const authors = book.metadata?.authors || [];
- return (title && normalize(title).includes(normalizedQuery)) ||
- authors.some(author => normalize(author).includes(normalizedQuery));
- });
- }
-
getFileContent(bookId: number): Observable {
return this.http.get(`${this.url}/${bookId}/content`, {responseType: 'blob' as 'json'});
}
@@ -331,7 +316,7 @@ export class BookService {
if (currentState.books) {
const updatedBooks = currentState.books.map(book => {
if (book.id === bookId) {
- return { ...book, dateFinished: dateFinished || undefined };
+ return {...book, dateFinished: dateFinished || undefined};
}
return book;
});