More css stuffs

This commit is contained in:
aditya.chandel
2024-12-29 01:37:25 -07:00
parent 40396c4889
commit bff16d6673
4 changed files with 32 additions and 29 deletions
@@ -28,7 +28,7 @@ public class BookController {
} }
@GetMapping @GetMapping
public ResponseEntity<List<BookDTO>> getBooks() throws InterruptedException { public ResponseEntity<List<BookDTO>> getBooks() {
return ResponseEntity.ok(booksService.getBooks()); return ResponseEntity.ok(booksService.getBooks());
} }
@@ -27,8 +27,10 @@
</div> </div>
<div class="virtual-scroller-container"> <div class="virtual-scroller-container">
<div *ngIf="(bookState$ | async)?.error"> <div class="no-books-container" *ngIf="(bookState$ | async)?.error">
<p class="no-books-text">Failed to load library's books!</p> <p class="no-books-text">
{{ entityType === 'Library' ? "Failed to load library's books!" : "Failed to load shelf's books!" }}
</p>
</div> </div>
<div class="no-books-container" *ngIf="!(bookState$ | async)?.error && (bookState$ | async)?.loaded && (bookState$ | async)?.books?.length === 0"> <div class="no-books-container" *ngIf="!(bookState$ | async)?.error && (bookState$ | async)?.loaded && (bookState$ | async)?.books?.length === 0">
<p class="no-books-text"> <p class="no-books-text">
@@ -1,9 +1,9 @@
import { Injectable } from '@angular/core'; import {Injectable} from '@angular/core';
import { BehaviorSubject, Observable, of } from 'rxjs'; import {BehaviorSubject, Observable, of} from 'rxjs';
import { HttpClient } from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import { catchError, map, switchMap } from 'rxjs/operators'; import {catchError, map, switchMap, tap} from 'rxjs/operators';
import { Book, BookMetadata, BookSetting } from '../model/book.model'; import {Book, BookMetadata, BookSetting} from '../model/book.model';
import { BookState } from '../model/state/book-state.model'; import {BookState} from '../model/state/book-state.model';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -24,6 +24,13 @@ export class BookService {
private loadBooks(): void { private loadBooks(): void {
this.http.get<Book[]>(this.url).pipe( this.http.get<Book[]>(this.url).pipe(
tap(books => {
this.bookStateSubject.next({
books: books || [],
loaded: true,
error: null,
});
}),
catchError(error => { catchError(error => {
this.bookStateSubject.next({ this.bookStateSubject.next({
books: null, books: null,
@@ -32,13 +39,7 @@ export class BookService {
}); });
return of(null); return of(null);
}) })
).subscribe(books => { ).subscribe();
this.bookStateSubject.next({
books: books || [],
loaded: true,
error: null,
});
});
} }
updateBookShelves(bookIds: Set<number | undefined>, shelvesToAssign: Set<number | undefined>, shelvesToUnassign: Set<number | undefined>): Observable<Book[]> { updateBookShelves(bookIds: Set<number | undefined>, shelvesToAssign: Set<number | undefined>, shelvesToUnassign: Set<number | undefined>): Observable<Book[]> {
@@ -57,12 +58,12 @@ export class BookService {
currentBooks[index] = updatedBook; currentBooks[index] = updatedBook;
} }
}); });
this.bookStateSubject.next({ ...currentState, books: [...currentBooks] }); this.bookStateSubject.next({...currentState, books: [...currentBooks]});
return updatedBooks; return updatedBooks;
}), }),
catchError(error => { catchError(error => {
const currentState = this.bookStateSubject.value; const currentState = this.bookStateSubject.value;
this.bookStateSubject.next({ ...currentState, error: error.message }); this.bookStateSubject.next({...currentState, error: error.message});
throw error; throw error;
}) })
); );
@@ -72,7 +73,7 @@ export class BookService {
const currentState = this.bookStateSubject.value; const currentState = this.bookStateSubject.value;
const currentBooks = currentState.books || []; const currentBooks = currentState.books || [];
const filteredBooks = currentBooks.filter(book => book.libraryId !== libraryId); const filteredBooks = currentBooks.filter(book => book.libraryId !== libraryId);
this.bookStateSubject.next({ ...currentState, books: filteredBooks }); this.bookStateSubject.next({...currentState, books: filteredBooks});
} }
removeBooksFromShelf(shelfId: number): void { removeBooksFromShelf(shelfId: number): void {
@@ -82,7 +83,7 @@ export class BookService {
...book, ...book,
shelves: book.shelves?.filter(shelf => shelf.id !== shelfId), shelves: book.shelves?.filter(shelf => shelf.id !== shelfId),
})); }));
this.bookStateSubject.next({ ...currentState, books: updatedBooks }); this.bookStateSubject.next({...currentState, books: updatedBooks});
} }
getBookById(bookId: number): Observable<Book | undefined> { getBookById(bookId: number): Observable<Book | undefined> {
@@ -104,9 +105,9 @@ export class BookService {
switchMap(updatedBook => { switchMap(updatedBook => {
const currentState = this.bookStateSubject.value; const currentState = this.bookStateSubject.value;
const updatedBooks = (currentState.books || []).map(book => 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]; return [updatedBook];
}) })
); );
@@ -150,19 +151,19 @@ export class BookService {
} }
setBookMetadata(googleBookId: string, bookId: number): Observable<Book> { setBookMetadata(googleBookId: string, bookId: number): Observable<Book> {
const requestBody = { googleBookId }; const requestBody = {googleBookId};
return this.http.put<Book>(`${this.url}/${bookId}/set-metadata`, requestBody).pipe( return this.http.put<Book>(`${this.url}/${bookId}/set-metadata`, requestBody).pipe(
map(book => { map(book => {
const currentState = this.bookStateSubject.value; const currentState = this.bookStateSubject.value;
const updatedBooks = (currentState.books || []).map(existingBook => const updatedBooks = (currentState.books || []).map(existingBook =>
existingBook.id === book.id ? book : existingBook existingBook.id === book.id ? book : existingBook
); );
this.bookStateSubject.next({ ...currentState, books: updatedBooks }); this.bookStateSubject.next({...currentState, books: updatedBooks});
return book; return book;
}), }),
catchError(error => { catchError(error => {
const currentState = this.bookStateSubject.value; const currentState = this.bookStateSubject.value;
this.bookStateSubject.next({ ...currentState, error: error.message }); this.bookStateSubject.next({...currentState, error: error.message});
throw error; throw error;
}) })
); );
@@ -177,12 +178,12 @@ export class BookService {
} else { } else {
updatedBooks.push(book); updatedBooks.push(book);
} }
this.bookStateSubject.next({ ...currentState, books: updatedBooks }); this.bookStateSubject.next({...currentState, books: updatedBooks});
} }
handleRemovedBookIds(removedBookIds: Set<number>): void { handleRemovedBookIds(removedBookIds: Set<number>): void {
const currentState = this.bookStateSubject.value; const currentState = this.bookStateSubject.value;
const filteredBooks = (currentState.books || []).filter(book => !removedBookIds.has(book.id)); const filteredBooks = (currentState.books || []).filter(book => !removedBookIds.has(book.id));
this.bookStateSubject.next({ ...currentState, books: filteredBooks }); this.bookStateSubject.next({...currentState, books: filteredBooks});
} }
} }
@@ -10,7 +10,7 @@
transition: transform $transitionDuration, left $transitionDuration; transition: transform $transitionDuration, left $transitionDuration;
background-color: var(--surface-overlay); background-color: var(--surface-overlay);
border-radius: $borderRadius; 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); 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; outline: 0 none;
color: var(--text-color); color: var(--text-color);
cursor: pointer; cursor: pointer;
padding: .75rem 1rem; padding: 0.75rem 0.5rem 0.75rem 1rem;
border-radius: $borderRadius; border-radius: $borderRadius;
transition: background-color $transitionDuration, box-shadow $transitionDuration; transition: background-color $transitionDuration, box-shadow $transitionDuration;