diff --git a/booklore-ui/src/app/book/component/books-browser/books-browser.component.ts b/booklore-ui/src/app/book/component/books-browser/books-browser.component.ts index 720f7d9f5..61daa4c12 100644 --- a/booklore-ui/src/app/book/component/books-browser/books-browser.component.ts +++ b/booklore-ui/src/app/book/component/books-browser/books-browser.component.ts @@ -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); } }); diff --git a/booklore-ui/src/app/book/service/library-and-book.service.ts b/booklore-ui/src/app/book/service/library-and-book.service.ts index 524ecdbb7..64a1b7ec4 100644 --- a/booklore-ui/src/app/book/service/library-and-book.service.ts +++ b/booklore-ui/src/app/book/service/library-and-book.service.ts @@ -121,6 +121,24 @@ export class LibraryAndBookService { ); } + loadLibraryBooks(libraryId: number) { + if (!this.loadedLibraries.has(libraryId)) { + this.http.get(`${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 { return this.http.delete(`${this.libraryUrl}/${libraryId}`).pipe( tap(() => { @@ -182,24 +200,6 @@ export class LibraryAndBookService { }); } - loadBooksSignal(libraryId: number) { - if (!this.loadedLibraries.has(libraryId)) { - this.http.get(`${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(`${this.bookUrl}/${bookId}/set-metadata`, requestBody); } - - }