Move book card to own component

WIP: Edit Book's shelf functionality
This commit is contained in:
aditya.chandel
2024-12-20 23:49:32 -07:00
parent c72301f6c6
commit 1abe138dd1
16 changed files with 259 additions and 101 deletions
@@ -1,5 +1,5 @@
import {Observable, of} from 'rxjs';
import {Book, BookMetadata, BookSetting, BookWithNeighborsDTO} from '../model/book.model';
import {Book, BookMetadata, BookSetting, BookWithNeighborsDTO, Shelf} from '../model/book.model';
import {computed, Injectable, signal} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {catchError, map, tap} from 'rxjs/operators';
@@ -11,10 +11,14 @@ import {Library, LibraryApiResponse} from '../model/library.model';
export class LibraryAndBookService {
private readonly libraryUrl = 'http://localhost:8080/v1/library';
private readonly bookUrl = 'http://localhost:8080/v1/book';
private readonly shelfUrl = 'http://localhost:8080/v1/shelf';
#libraries = signal<Library[]>([]);
libraries = computed(this.#libraries);
#shelves = signal<Shelf[]>([]);
shelves = computed(this.#shelves);
#lastReadBooks = signal<Book[]>([]);
lastReadBooks = computed(this.#lastReadBooks);
lastReadBooksLoaded: boolean = false;
@@ -31,6 +35,24 @@ export class LibraryAndBookService {
}
/*---------- Shelf Methods go below ----------*/
initializeShelves(): void {
this.http.get<Shelf[]>(this.shelfUrl).pipe(
map(response => response),
catchError(error => {
console.error('Error loading libraries:', error);
return of([]);
})
).subscribe(
(shelves) => {
this.#shelves.set(shelves);
console.log("Library Initialized")
}
);
}
/*---------- Library Methods go below ----------*/
initializeLibraries(): void {