No need to subscribe for book search.

This commit is contained in:
aditya.chandel
2025-01-23 13:22:56 -07:00
parent 53d394fbbe
commit 0a7140e5aa
3 changed files with 16 additions and 26 deletions
@@ -178,17 +178,14 @@ export class BookService {
}
}
searchBooks(query: string): Observable<Book[]> {
searchBooks(query: string): Book[] {
if (query.length < 2) {
return of([]);
return [];
}
return this.bookState$.pipe(
map(state =>
(state.books || []).filter(book =>
(book.metadata?.title?.toLowerCase().includes(query.toLowerCase()) ||
book.metadata?.authors.some(author => author.name.toLowerCase().includes(query.toLowerCase())))
)
)
const state = this.bookStateSubject.value;
return (state.books || []).filter(book =>
book.metadata?.title?.toLowerCase().includes(query.toLowerCase()) ||
book.metadata?.authors.some(author => author.name.toLowerCase().includes(query.toLowerCase()))
);
}