Use local data source for searching

This commit is contained in:
aditya.chandel
2024-12-25 14:18:14 -07:00
parent cd2207f01e
commit 8d7eb8c460
2 changed files with 8 additions and 6 deletions
@@ -75,7 +75,7 @@ export class BookService {
console.log(updatedBook);
const currentBooks = this.books.getValue();
const updatedBooks = currentBooks.map(book =>
book.id === updatedBook.id ? { ...book, lastReadTime: updatedBook.lastReadTime } : book
book.id === updatedBook.id ? {...book, lastReadTime: updatedBook.lastReadTime} : book
);
this.books.next(updatedBooks);
return [updatedBook];
@@ -97,7 +97,10 @@ export class BookService {
if (query.length < 2) {
return of([]);
}
return this.http.get<Book[]>(`${this.url}/search?title=${encodeURIComponent(query)}`);
const filteredBooks = this.books.value.filter(book =>
book.metadata?.title?.toLowerCase().includes(query.toLowerCase()) || false
);
return of(filteredBooks);
}
getBookDataUrl(bookId: number): string {