Rename method name
This commit is contained in:
@@ -48,11 +48,11 @@ export class BooksBrowserComponent implements OnInit {
|
||||
if (libraryId) {
|
||||
this.entityType.set('library');
|
||||
this.currentEntityId.set(libraryId);
|
||||
this.libraryBookService.loadBooksSignal(libraryId);
|
||||
this.libraryBookService.loadLibraryBooks(libraryId);
|
||||
} else if (shelfId) {
|
||||
this.entityType.set('shelf');
|
||||
this.currentEntityId.set(shelfId);
|
||||
this.libraryBookService.loadBooksSignal(shelfId);
|
||||
this.libraryBookService.loadLibraryBooks(shelfId);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -121,6 +121,24 @@ export class LibraryAndBookService {
|
||||
);
|
||||
}
|
||||
|
||||
loadLibraryBooks(libraryId: number) {
|
||||
if (!this.loadedLibraries.has(libraryId)) {
|
||||
this.http.get<Book[]>(`${this.libraryUrl}/${libraryId}/book`).pipe(
|
||||
map(response => response),
|
||||
catchError(error => {
|
||||
console.error(`Error loading books for library ${libraryId}:`, error);
|
||||
return of([]);
|
||||
})
|
||||
).subscribe((books) => {
|
||||
const updatedMap = new Map(this.libraryBooksMap());
|
||||
updatedMap.set(libraryId, books);
|
||||
this.libraryBooksMap.set(updatedMap);
|
||||
this.loadedLibraries.add(libraryId);
|
||||
console.log(`Loaded books for library ${libraryId}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
deleteLibrary(libraryId: number | null): Observable<void> {
|
||||
return this.http.delete<void>(`${this.libraryUrl}/${libraryId}`).pipe(
|
||||
tap(() => {
|
||||
@@ -182,24 +200,6 @@ export class LibraryAndBookService {
|
||||
});
|
||||
}
|
||||
|
||||
loadBooksSignal(libraryId: number) {
|
||||
if (!this.loadedLibraries.has(libraryId)) {
|
||||
this.http.get<Book[]>(`${this.libraryUrl}/${libraryId}/book`).pipe(
|
||||
map(response => response),
|
||||
catchError(error => {
|
||||
console.error(`Error loading books for library ${libraryId}:`, error);
|
||||
return of([]);
|
||||
})
|
||||
).subscribe((books) => {
|
||||
const updatedMap = new Map(this.libraryBooksMap());
|
||||
updatedMap.set(libraryId, books);
|
||||
this.libraryBooksMap.set(updatedMap);
|
||||
this.loadedLibraries.add(libraryId);
|
||||
console.log(`Loaded books for library ${libraryId}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
handleNewBook(book: Book) {
|
||||
const newBook: Book = this.convertBookDTOToBook(book);
|
||||
const updatedMap = new Map(this.libraryBooksMap());
|
||||
@@ -310,6 +310,4 @@ export class LibraryAndBookService {
|
||||
const requestBody = {googleBookId: googleBookId};
|
||||
return this.http.put<void>(`${this.bookUrl}/${bookId}/set-metadata`, requestBody);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user