Add spinner and fix csses
This commit is contained in:
+1
-3
@@ -2,8 +2,8 @@ package com.adityachandel.booklore.controller;
|
|||||||
|
|
||||||
import com.adityachandel.booklore.model.dto.BookDTO;
|
import com.adityachandel.booklore.model.dto.BookDTO;
|
||||||
import com.adityachandel.booklore.model.dto.BookViewerSettingDTO;
|
import com.adityachandel.booklore.model.dto.BookViewerSettingDTO;
|
||||||
import com.adityachandel.booklore.model.dto.request.ShelvesAssignmentRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.SetMetadataRequest;
|
import com.adityachandel.booklore.model.dto.request.SetMetadataRequest;
|
||||||
|
import com.adityachandel.booklore.model.dto.request.ShelvesAssignmentRequest;
|
||||||
import com.adityachandel.booklore.model.dto.response.GoogleBooksMetadata;
|
import com.adityachandel.booklore.model.dto.response.GoogleBooksMetadata;
|
||||||
import com.adityachandel.booklore.service.BooksService;
|
import com.adityachandel.booklore.service.BooksService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
@@ -13,7 +13,6 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RequestMapping("/v1/book")
|
@RequestMapping("/v1/book")
|
||||||
@@ -30,7 +29,6 @@ public class BookController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<List<BookDTO>> getBooks() throws InterruptedException {
|
public ResponseEntity<List<BookDTO>> getBooks() throws InterruptedException {
|
||||||
Thread.sleep(Duration.ofSeconds(3));
|
|
||||||
return ResponseEntity.ok(booksService.getBooks());
|
return ResponseEntity.ok(booksService.getBooks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import {RouteReuseStrategy} from '@angular/router';
|
|||||||
import {CustomReuseStrategy} from './custom-reuse-strategy';
|
import {CustomReuseStrategy} from './custom-reuse-strategy';
|
||||||
import {MenuModule} from 'primeng/menu';
|
import {MenuModule} from 'primeng/menu';
|
||||||
import {IconPickerComponent} from './book/component/icon-picker/icon-picker.component';
|
import {IconPickerComponent} from './book/component/icon-picker/icon-picker.component';
|
||||||
|
import {ProgressSpinnerModule} from 'primeng/progressspinner';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -73,6 +74,7 @@ import {IconPickerComponent} from './book/component/icon-picker/icon-picker.comp
|
|||||||
SpeedDialModule,
|
SpeedDialModule,
|
||||||
MenuModule,
|
MenuModule,
|
||||||
IconPickerComponent,
|
IconPickerComponent,
|
||||||
|
ProgressSpinnerModule,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
DialogService,
|
DialogService,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
<div>
|
||||||
<div class="book-browser-header">
|
<div class="book-browser-header">
|
||||||
<div class="flex align-items-center">
|
<div class="flex align-items-center">
|
||||||
<h4 class="entity-name">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</h4>
|
<h4 class="entity-name">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</h4>
|
||||||
@@ -21,7 +22,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="!(bookState$ | async)?.loaded && !(bookState$ | async)?.error">
|
||||||
|
<p-progressSpinner></p-progressSpinner>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="virtual-scroller-container">
|
<div class="virtual-scroller-container">
|
||||||
|
<div *ngIf="(bookState$ | async)?.error">
|
||||||
|
<p class="no-books-text">Failed to load library's books!</p>
|
||||||
|
</div>
|
||||||
|
<div class="no-books-container" *ngIf="!(bookState$ | async)?.error && (bookState$ | async)?.loaded && (bookState$ | async)?.books?.length === 0">
|
||||||
|
<p class="no-books-text">
|
||||||
|
{{ entityType === 'Library' ? "This library has no books!" : "This shelf has no books!" }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<div class="book-card-container" *ngIf="(bookState$ | async)?.books as books">
|
<div class="book-card-container" *ngIf="(bookState$ | async)?.books as books">
|
||||||
<virtual-scroller *ngIf="books.length > 0" class="virtual-scroller" #scroll [items]="books">
|
<virtual-scroller *ngIf="books.length > 0" class="virtual-scroller" #scroll [items]="books">
|
||||||
<div class="grid" #container>
|
<div class="grid" #container>
|
||||||
@@ -35,9 +48,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</virtual-scroller>
|
</virtual-scroller>
|
||||||
<div *ngIf="books.length === 0" class="empty-message">
|
|
||||||
<p>No books available to display.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
||||||
<div class="footer-items-container">
|
<div class="footer-items-container">
|
||||||
@@ -48,3 +58,5 @@
|
|||||||
<p-menu #menu [model]="multiSelectItems" [popup]="true" appendTo="body"></p-menu>
|
<p-menu #menu [model]="multiSelectItems" [popup]="true" appendTo="body"></p-menu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -25,10 +25,23 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.virtual-scroller-container {
|
.virtual-scroller-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-books-text {
|
||||||
|
font-size: 1rem;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-books-container {
|
||||||
|
padding-top: 3rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.virtual-scroller {
|
.virtual-scroller {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100vh - 11.5rem);
|
height: calc(100vh - 11.5rem);
|
||||||
@@ -72,3 +85,4 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {SortService} from '../../service/sort.service';
|
|||||||
import {SortOptionsHelper} from '../../service/sort-options.helper';
|
import {SortOptionsHelper} from '../../service/sort-options.helper';
|
||||||
import {SortOption} from '../../model/sort.model';
|
import {SortOption} from '../../model/sort.model';
|
||||||
import {BookState} from '../../model/state/book-state.model';
|
import {BookState} from '../../model/state/book-state.model';
|
||||||
|
import {Book} from '../../model/book.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-books-browser',
|
selector: 'app-books-browser',
|
||||||
@@ -56,7 +57,7 @@ export class BooksBrowserComponent implements OnInit {
|
|||||||
const routeParam$ = this.getRouteParams();
|
const routeParam$ = this.getRouteParams();
|
||||||
|
|
||||||
this.bookState$ = routeParam$.pipe(
|
this.bookState$ = routeParam$.pipe(
|
||||||
switchMap(({libraryId, shelfId}) => this.fetchBooks(libraryId, shelfId)),
|
switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId)),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entity$ = routeParam$.pipe(
|
this.entity$ = routeParam$.pipe(
|
||||||
@@ -90,19 +91,6 @@ export class BooksBrowserComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchBooks(libraryId: number, shelfId: number): Observable<BookState> {
|
|
||||||
if (libraryId) {
|
|
||||||
return this.fetchBooksByLibrary(libraryId);
|
|
||||||
} else if (shelfId) {
|
|
||||||
return this.fetchBooksByShelf(shelfId);
|
|
||||||
}
|
|
||||||
return of({
|
|
||||||
books: [],
|
|
||||||
loaded: false,
|
|
||||||
error: null
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private fetchEntity(libraryId: number, shelfId: number): Observable<Library | Shelf | null> {
|
private fetchEntity(libraryId: number, shelfId: number): Observable<Library | Shelf | null> {
|
||||||
if (libraryId) {
|
if (libraryId) {
|
||||||
this.entityType = 'Library';
|
this.entityType = 'Library';
|
||||||
@@ -116,67 +104,53 @@ export class BooksBrowserComponent implements OnInit {
|
|||||||
return of(null);
|
return of(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchBooksByLibrary(libraryId: number): Observable<BookState> {
|
private fetchBooksByEntity(libraryId: number, shelfId: number): Observable<BookState> {
|
||||||
return this.bookService.bookState$.pipe(
|
if (libraryId) {
|
||||||
map(bookState => {
|
return this.fetchBooksByLibrary(libraryId);
|
||||||
if (bookState.books) {
|
} else if (shelfId) {
|
||||||
const filteredBooks = bookState.books.filter(book => book.libraryId === libraryId);
|
return this.fetchBooksByShelf(shelfId);
|
||||||
return this.sortService.applySort(filteredBooks, this.selectedSort);
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
}),
|
return of({
|
||||||
switchMap(books =>
|
books: null,
|
||||||
this.bookTitle$.pipe(
|
|
||||||
map(title => {
|
|
||||||
if (title && title.trim() !== '') {
|
|
||||||
return books.filter(book => book.metadata?.title?.toLowerCase().includes(title.toLowerCase()));
|
|
||||||
}
|
|
||||||
return books;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
),
|
|
||||||
map(filteredBooks => {
|
|
||||||
return {
|
|
||||||
books: filteredBooks,
|
|
||||||
loaded: true,
|
loaded: true,
|
||||||
error: null
|
error: 'Invalid entity type'
|
||||||
} as BookState;
|
});
|
||||||
})
|
}
|
||||||
);
|
|
||||||
|
private fetchBooksByLibrary(libraryId: number): Observable<BookState> {
|
||||||
|
return this.fetchBooks(book => book.libraryId === libraryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private fetchBooksByShelf(shelfId: number): Observable<BookState> {
|
private fetchBooksByShelf(shelfId: number): Observable<BookState> {
|
||||||
|
return this.fetchBooks(book => {
|
||||||
|
return book.shelves?.some(shelf => shelf.id === shelfId) ?? false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchBooks(bookFilter: (book: Book) => boolean): Observable<BookState> {
|
||||||
return this.bookService.bookState$.pipe(
|
return this.bookService.bookState$.pipe(
|
||||||
map(bookState => {
|
map(bookState => {
|
||||||
if (bookState.books) {
|
if (bookState.loaded && !bookState.error) {
|
||||||
const filteredBooks = bookState.books.filter(book =>
|
const filteredBooks = bookState.books!.filter(book => {
|
||||||
book.shelves?.some(shelf => shelf.id === shelfId)
|
return bookFilter(book);
|
||||||
);
|
});
|
||||||
return this.sortService.applySort(filteredBooks, this.selectedSort);
|
const sortedBooks = this.sortService.applySort(filteredBooks, this.selectedSort);
|
||||||
|
return { ...bookState, books: sortedBooks };
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return bookState;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
switchMap(books =>
|
switchMap(bookState =>
|
||||||
this.bookTitle$.pipe(
|
this.bookTitle$.pipe(
|
||||||
map(title => {
|
map(title => {
|
||||||
if (title && title.trim() !== '') {
|
if (title && title.trim() !== '') {
|
||||||
return books.filter(book =>
|
const filteredBooks = bookState.books?.filter(book => book.metadata?.title?.toLowerCase().includes(title.toLowerCase())) || null;
|
||||||
book.metadata?.title?.toLowerCase().includes(title.toLowerCase())
|
return { ...bookState, books: filteredBooks };
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return books;
|
return bookState;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
map(filteredBooks => {
|
|
||||||
return {
|
|
||||||
books: filteredBooks,
|
|
||||||
loaded: true,
|
|
||||||
error: null
|
|
||||||
} as BookState;
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +208,7 @@ export class BooksBrowserComponent implements OnInit {
|
|||||||
this.selectedSort = sortOption;
|
this.selectedSort = sortOption;
|
||||||
const routeParam$ = this.getRouteParams();
|
const routeParam$ = this.getRouteParams();
|
||||||
this.bookState$ = routeParam$.pipe(
|
this.bookState$ = routeParam$.pipe(
|
||||||
switchMap(({libraryId, shelfId}) => this.fetchBooks(libraryId, shelfId))
|
switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId))
|
||||||
);
|
);
|
||||||
if (this.entityType === 'Library') {
|
if (this.entityType === 'Library') {
|
||||||
this.libraryService.updateSort(this.entity?.id!, sortOption).subscribe();
|
this.libraryService.updateSort(this.entity?.id!, sortOption).subscribe();
|
||||||
|
|||||||
+16
-2
@@ -1,8 +1,21 @@
|
|||||||
<div class="dashboard-scroller-container">
|
<div class="dashboard-scroller-container">
|
||||||
|
|
||||||
<h2 class="dashboard-scroller-title">{{ title }}</h2>
|
<h2 class="dashboard-scroller-title">{{ title }}</h2>
|
||||||
<div *ngIf="(bookState$ | async)?.books?.length === 0">
|
|
||||||
<h4>No books available.</h4>
|
<div class="no-books-container" *ngIf="!(bookState$ | async)?.error && (bookState$ | async)?.loaded && (bookState$ | async)?.books?.length === 0">
|
||||||
|
<p class="no-books-text">
|
||||||
|
{{ bookListType === 'lastRead' ? "You haven't read any books yet!" : "No books have been added to BookLore!" }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="no-books-container" *ngIf="(bookState$ | async)?.error">
|
||||||
|
<p class="no-books-text">Failed to load books! :(</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="!(bookState$ | async)?.loaded && !(bookState$ | async)?.error">
|
||||||
|
<p-progressSpinner></p-progressSpinner>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="infinite-scroller"
|
<div class="infinite-scroller"
|
||||||
infiniteScroll
|
infiniteScroll
|
||||||
[infiniteScrollDistance]="2"
|
[infiniteScrollDistance]="2"
|
||||||
@@ -13,4 +26,5 @@
|
|||||||
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
|
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+13
@@ -10,6 +10,18 @@
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-books-text {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-books-container {
|
||||||
|
padding-top: 3rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.infinite-scroller {
|
.infinite-scroller {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -30,3 +42,4 @@
|
|||||||
scroll-snap-align: start;
|
scroll-snap-align: start;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -6,6 +6,7 @@ import { BookState } from '../../model/state/book-state.model';
|
|||||||
import { BookCardComponent } from '../book-card/book-card.component';
|
import { BookCardComponent } from '../book-card/book-card.component';
|
||||||
import { InfiniteScrollDirective } from 'ngx-infinite-scroll';
|
import { InfiniteScrollDirective } from 'ngx-infinite-scroll';
|
||||||
import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
|
import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
|
||||||
|
import {ProgressSpinnerModule} from 'primeng/progressspinner';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard-scroller',
|
selector: 'app-dashboard-scroller',
|
||||||
@@ -16,7 +17,8 @@ import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
|
|||||||
NgForOf,
|
NgForOf,
|
||||||
NgIf,
|
NgIf,
|
||||||
BookCardComponent,
|
BookCardComponent,
|
||||||
AsyncPipe
|
AsyncPipe,
|
||||||
|
ProgressSpinnerModule
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class DashboardScrollerComponent implements OnInit {
|
export class DashboardScrollerComponent implements OnInit {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<div class="flex flex-column xxx">
|
<div class="flex flex-column xxx">
|
||||||
<div
|
<div
|
||||||
class="border-2 border-dashed surface-border border-round surface-ground flex-auto flex align-items-start"
|
class="border-2 border-dashed surface-border border-round surface-ground flex-auto flex align-items-start"
|
||||||
style="padding-top: 2.5rem;">
|
style="padding-top: 3rem;">
|
||||||
<div class="flex flex-column justify-content-center align-items-center w-100">
|
<div class="flex flex-column justify-content-center align-items-center w-100">
|
||||||
<p-button
|
<p-button
|
||||||
severity="secondary"
|
severity="secondary"
|
||||||
|
|||||||
Reference in New Issue
Block a user