Use local data source for searching
This commit is contained in:
@@ -25,8 +25,6 @@ export class BooksBrowserComponent implements OnInit {
|
|||||||
items: MenuItem[] | undefined;
|
items: MenuItem[] | undefined;
|
||||||
selectedBooks: Set<number> = new Set();
|
selectedBooks: Set<number> = new Set();
|
||||||
entity: Library | Shelf | null = null;
|
entity: Library | Shelf | null = null;
|
||||||
private deselectAllSubject = new Subject<void>(); // Subject to notify deselection
|
|
||||||
deselectAll$ = this.deselectAllSubject.asObservable();
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private activatedRoute: ActivatedRoute,
|
private activatedRoute: ActivatedRoute,
|
||||||
@@ -92,15 +90,16 @@ export class BooksBrowserComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.entity$.subscribe(entity => {
|
this.entity$.subscribe(entity => {
|
||||||
this.entity = entity; // Store resolved value in local variable
|
this.entity = entity;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.setupMenu();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleBookSelect(bookId: number, selected: boolean): void {
|
handleBookSelect(bookId: number, selected: boolean): void {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
this.selectedBooks.add(bookId);
|
this.selectedBooks.add(bookId);
|
||||||
this.setupMenu();
|
|
||||||
} else {
|
} else {
|
||||||
this.selectedBooks.delete(bookId);
|
this.selectedBooks.delete(bookId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export class BookService {
|
|||||||
console.log(updatedBook);
|
console.log(updatedBook);
|
||||||
const currentBooks = this.books.getValue();
|
const currentBooks = this.books.getValue();
|
||||||
const updatedBooks = currentBooks.map(book =>
|
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);
|
this.books.next(updatedBooks);
|
||||||
return [updatedBook];
|
return [updatedBook];
|
||||||
@@ -97,7 +97,10 @@ export class BookService {
|
|||||||
if (query.length < 2) {
|
if (query.length < 2) {
|
||||||
return of([]);
|
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 {
|
getBookDataUrl(bookId: number): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user