From bff16d66734e0bd01e745d846e4332973b3e27e0 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Sun, 29 Dec 2024 01:37:25 -0700 Subject: [PATCH] More css stuffs --- .../booklore/controller/BookController.java | 2 +- .../books-browser.component.html | 6 ++- .../src/app/book/service/book.service.ts | 49 ++++++++++--------- .../assets/layout/styles/layout/_menu.scss | 4 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/controller/BookController.java b/booklore-api/src/main/java/com/adityachandel/booklore/controller/BookController.java index 87b4c6671..d5ced55d8 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/controller/BookController.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/controller/BookController.java @@ -28,7 +28,7 @@ public class BookController { } @GetMapping - public ResponseEntity> getBooks() throws InterruptedException { + public ResponseEntity> getBooks() { return ResponseEntity.ok(booksService.getBooks()); } diff --git a/booklore-ui/src/app/book/component/books-browser/books-browser.component.html b/booklore-ui/src/app/book/component/books-browser/books-browser.component.html index d04757a13..1ecab8a26 100644 --- a/booklore-ui/src/app/book/component/books-browser/books-browser.component.html +++ b/booklore-ui/src/app/book/component/books-browser/books-browser.component.html @@ -27,8 +27,10 @@
-
-

Failed to load library's books!

+
+

+ {{ entityType === 'Library' ? "Failed to load library's books!" : "Failed to load shelf's books!" }} +

diff --git a/booklore-ui/src/app/book/service/book.service.ts b/booklore-ui/src/app/book/service/book.service.ts index 946c66819..062697eb7 100644 --- a/booklore-ui/src/app/book/service/book.service.ts +++ b/booklore-ui/src/app/book/service/book.service.ts @@ -1,9 +1,9 @@ -import { Injectable } from '@angular/core'; -import { BehaviorSubject, Observable, of } from 'rxjs'; -import { HttpClient } from '@angular/common/http'; -import { catchError, map, switchMap } from 'rxjs/operators'; -import { Book, BookMetadata, BookSetting } from '../model/book.model'; -import { BookState } from '../model/state/book-state.model'; +import {Injectable} from '@angular/core'; +import {BehaviorSubject, Observable, of} from 'rxjs'; +import {HttpClient} from '@angular/common/http'; +import {catchError, map, switchMap, tap} from 'rxjs/operators'; +import {Book, BookMetadata, BookSetting} from '../model/book.model'; +import {BookState} from '../model/state/book-state.model'; @Injectable({ providedIn: 'root', @@ -24,6 +24,13 @@ export class BookService { private loadBooks(): void { this.http.get(this.url).pipe( + tap(books => { + this.bookStateSubject.next({ + books: books || [], + loaded: true, + error: null, + }); + }), catchError(error => { this.bookStateSubject.next({ books: null, @@ -32,13 +39,7 @@ export class BookService { }); return of(null); }) - ).subscribe(books => { - this.bookStateSubject.next({ - books: books || [], - loaded: true, - error: null, - }); - }); + ).subscribe(); } updateBookShelves(bookIds: Set, shelvesToAssign: Set, shelvesToUnassign: Set): Observable { @@ -57,12 +58,12 @@ export class BookService { currentBooks[index] = updatedBook; } }); - this.bookStateSubject.next({ ...currentState, books: [...currentBooks] }); + this.bookStateSubject.next({...currentState, books: [...currentBooks]}); return updatedBooks; }), catchError(error => { const currentState = this.bookStateSubject.value; - this.bookStateSubject.next({ ...currentState, error: error.message }); + this.bookStateSubject.next({...currentState, error: error.message}); throw error; }) ); @@ -72,7 +73,7 @@ export class BookService { const currentState = this.bookStateSubject.value; const currentBooks = currentState.books || []; const filteredBooks = currentBooks.filter(book => book.libraryId !== libraryId); - this.bookStateSubject.next({ ...currentState, books: filteredBooks }); + this.bookStateSubject.next({...currentState, books: filteredBooks}); } removeBooksFromShelf(shelfId: number): void { @@ -82,7 +83,7 @@ export class BookService { ...book, shelves: book.shelves?.filter(shelf => shelf.id !== shelfId), })); - this.bookStateSubject.next({ ...currentState, books: updatedBooks }); + this.bookStateSubject.next({...currentState, books: updatedBooks}); } getBookById(bookId: number): Observable { @@ -104,9 +105,9 @@ export class BookService { switchMap(updatedBook => { const currentState = this.bookStateSubject.value; const updatedBooks = (currentState.books || []).map(book => - book.id === updatedBook.id ? { ...book, lastReadTime: updatedBook.lastReadTime } : book + book.id === updatedBook.id ? {...book, lastReadTime: updatedBook.lastReadTime} : book ); - this.bookStateSubject.next({ ...currentState, books: updatedBooks }); + this.bookStateSubject.next({...currentState, books: updatedBooks}); return [updatedBook]; }) ); @@ -150,19 +151,19 @@ export class BookService { } setBookMetadata(googleBookId: string, bookId: number): Observable { - const requestBody = { googleBookId }; + const requestBody = {googleBookId}; return this.http.put(`${this.url}/${bookId}/set-metadata`, requestBody).pipe( map(book => { const currentState = this.bookStateSubject.value; const updatedBooks = (currentState.books || []).map(existingBook => existingBook.id === book.id ? book : existingBook ); - this.bookStateSubject.next({ ...currentState, books: updatedBooks }); + this.bookStateSubject.next({...currentState, books: updatedBooks}); return book; }), catchError(error => { const currentState = this.bookStateSubject.value; - this.bookStateSubject.next({ ...currentState, error: error.message }); + this.bookStateSubject.next({...currentState, error: error.message}); throw error; }) ); @@ -177,12 +178,12 @@ export class BookService { } else { updatedBooks.push(book); } - this.bookStateSubject.next({ ...currentState, books: updatedBooks }); + this.bookStateSubject.next({...currentState, books: updatedBooks}); } handleRemovedBookIds(removedBookIds: Set): void { const currentState = this.bookStateSubject.value; const filteredBooks = (currentState.books || []).filter(book => !removedBookIds.has(book.id)); - this.bookStateSubject.next({ ...currentState, books: filteredBooks }); + this.bookStateSubject.next({...currentState, books: filteredBooks}); } } diff --git a/booklore-ui/src/assets/layout/styles/layout/_menu.scss b/booklore-ui/src/assets/layout/styles/layout/_menu.scss index ea744c45b..025098c6f 100644 --- a/booklore-ui/src/assets/layout/styles/layout/_menu.scss +++ b/booklore-ui/src/assets/layout/styles/layout/_menu.scss @@ -10,7 +10,7 @@ transition: transform $transitionDuration, left $transitionDuration; background-color: var(--surface-overlay); border-radius: $borderRadius; - padding: 0.5rem 1.5rem; + padding: 0.5rem 1.35rem; box-shadow: 0px 3px 5px rgba(0, 0, 0, .02), 0px 0px 2px rgba(0, 0, 0, .05), 0px 1px 4px rgba(0, 0, 0, .08); } @@ -63,7 +63,7 @@ outline: 0 none; color: var(--text-color); cursor: pointer; - padding: .75rem 1rem; + padding: 0.75rem 0.5rem 0.75rem 1rem; border-radius: $borderRadius; transition: background-color $transitionDuration, box-shadow $transitionDuration;