Add spinner and fix csses
This commit is contained in:
@@ -37,6 +37,7 @@ import {RouteReuseStrategy} from '@angular/router';
|
||||
import {CustomReuseStrategy} from './custom-reuse-strategy';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
import {IconPickerComponent} from './book/component/icon-picker/icon-picker.component';
|
||||
import {ProgressSpinnerModule} from 'primeng/progressspinner';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -73,6 +74,7 @@ import {IconPickerComponent} from './book/component/icon-picker/icon-picker.comp
|
||||
SpeedDialModule,
|
||||
MenuModule,
|
||||
IconPickerComponent,
|
||||
ProgressSpinnerModule,
|
||||
],
|
||||
providers: [
|
||||
DialogService,
|
||||
|
||||
@@ -1,50 +1,62 @@
|
||||
<div class="book-browser-header">
|
||||
<div class="flex align-items-center">
|
||||
<h4 class="entity-name">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</h4>
|
||||
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"/>
|
||||
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
||||
</div>
|
||||
|
||||
<div class="header-right-items">
|
||||
<input type="text" pInputText placeholder="Search by title..." [(ngModel)]="bookTitle" (ngModelChange)="onBookTitleChange($event)"/>
|
||||
<p-dropdown
|
||||
[options]="sortOptions"
|
||||
optionLabel="label"
|
||||
placeholder="Select Sorting"
|
||||
[(ngModel)]="selectedSort"
|
||||
(onChange)="updateSortOption($event.value)">
|
||||
</p-dropdown>
|
||||
<div class="zoom-controls">
|
||||
<p-button icon="pi pi-minus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
<div>
|
||||
<div class="book-browser-header">
|
||||
<div class="flex align-items-center">
|
||||
<h4 class="entity-name">{{ (entityType$ | async) }}: {{ (entity$ | async)?.name }}</h4>
|
||||
<p-button icon="pi pi-ellipsis-v" [rounded]="true" [text]="true" severity="info" (click)="entitymenu.toggle($event)"/>
|
||||
<p-menu #entitymenu [model]="entityOptions" [popup]="true" appendTo="body"></p-menu>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="virtual-scroller-container">
|
||||
<div class="book-card-container" *ngIf="(bookState$ | async)?.books as books">
|
||||
<virtual-scroller *ngIf="books.length > 0" class="virtual-scroller" #scroll [items]="books">
|
||||
<div class="grid" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<app-book-card
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[onBookSelect]="handleBookSelect.bind(this)"
|
||||
[isSelected]="selectedBooks.has(book.id)">
|
||||
</app-book-card>
|
||||
</div>
|
||||
<div class="header-right-items">
|
||||
<input type="text" pInputText placeholder="Search by title..." [(ngModel)]="bookTitle" (ngModelChange)="onBookTitleChange($event)"/>
|
||||
<p-dropdown
|
||||
[options]="sortOptions"
|
||||
optionLabel="label"
|
||||
placeholder="Select Sorting"
|
||||
[(ngModel)]="selectedSort"
|
||||
(onChange)="updateSortOption($event.value)">
|
||||
</p-dropdown>
|
||||
<div class="zoom-controls">
|
||||
<p-button icon="pi pi-minus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" [rounded]="true" [outlined]="true" severity="info"></p-button>
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
<div *ngIf="books.length === 0" class="empty-message">
|
||||
<p>No books available to display.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
||||
<div class="footer-items-container">
|
||||
<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-ellipsis-v" label="Options" severity="info" (click)="menu.toggle($event)"></p-button>
|
||||
<p-button *ngIf="(entityType$ | async) === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="info" (click)="unshelfBooks()"></p-button>
|
||||
<p-button icon="pi pi-times" label="Deselect" severity="warning" (click)="deselectAllBooks()"></p-button>
|
||||
</div>
|
||||
<p-menu #menu [model]="multiSelectItems" [popup]="true" appendTo="body"></p-menu>
|
||||
|
||||
<div *ngIf="!(bookState$ | async)?.loaded && !(bookState$ | async)?.error">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<virtual-scroller *ngIf="books.length > 0" class="virtual-scroller" #scroll [items]="books">
|
||||
<div class="grid" #container>
|
||||
<div class="virtual-scroller-item" *ngFor="let book of scroll.viewPortItems">
|
||||
<app-book-card
|
||||
[book]="book"
|
||||
[isCheckboxEnabled]="true"
|
||||
[onBookSelect]="handleBookSelect.bind(this)"
|
||||
[isSelected]="selectedBooks.has(book.id)">
|
||||
</app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
</virtual-scroller>
|
||||
</div>
|
||||
<div class="book-browser-footer" *ngIf="selectedBooks.size > 0">
|
||||
<div class="footer-items-container">
|
||||
<p-button *ngIf="(entityType$ | async) === 'Library'" icon="pi pi-ellipsis-v" label="Options" severity="info" (click)="menu.toggle($event)"></p-button>
|
||||
<p-button *ngIf="(entityType$ | async) === 'Shelf'" icon="pi pi-minus-circle" label="Unshelf" severity="info" (click)="unshelfBooks()"></p-button>
|
||||
<p-button icon="pi pi-times" label="Deselect" severity="warning" (click)="deselectAllBooks()"></p-button>
|
||||
</div>
|
||||
<p-menu #menu [model]="multiSelectItems" [popup]="true" appendTo="body"></p-menu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -25,10 +25,23 @@
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
.virtual-scroller-container {
|
||||
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 {
|
||||
width: 100%;
|
||||
height: calc(100vh - 11.5rem);
|
||||
@@ -72,3 +85,4 @@
|
||||
justify-content: space-between;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import {SortService} from '../../service/sort.service';
|
||||
import {SortOptionsHelper} from '../../service/sort-options.helper';
|
||||
import {SortOption} from '../../model/sort.model';
|
||||
import {BookState} from '../../model/state/book-state.model';
|
||||
import {Book} from '../../model/book.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-books-browser',
|
||||
@@ -56,7 +57,7 @@ export class BooksBrowserComponent implements OnInit {
|
||||
const routeParam$ = this.getRouteParams();
|
||||
|
||||
this.bookState$ = routeParam$.pipe(
|
||||
switchMap(({libraryId, shelfId}) => this.fetchBooks(libraryId, shelfId)),
|
||||
switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId)),
|
||||
);
|
||||
|
||||
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> {
|
||||
if (libraryId) {
|
||||
this.entityType = 'Library';
|
||||
@@ -116,67 +104,53 @@ export class BooksBrowserComponent implements OnInit {
|
||||
return of(null);
|
||||
}
|
||||
|
||||
private fetchBooksByEntity(libraryId: number, shelfId: number): Observable<BookState> {
|
||||
if (libraryId) {
|
||||
return this.fetchBooksByLibrary(libraryId);
|
||||
} else if (shelfId) {
|
||||
return this.fetchBooksByShelf(shelfId);
|
||||
}
|
||||
return of({
|
||||
books: null,
|
||||
loaded: true,
|
||||
error: 'Invalid entity type'
|
||||
});
|
||||
}
|
||||
|
||||
private fetchBooksByLibrary(libraryId: number): Observable<BookState> {
|
||||
return this.bookService.bookState$.pipe(
|
||||
map(bookState => {
|
||||
if (bookState.books) {
|
||||
const filteredBooks = bookState.books.filter(book => book.libraryId === libraryId);
|
||||
return this.sortService.applySort(filteredBooks, this.selectedSort);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}),
|
||||
switchMap(books =>
|
||||
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,
|
||||
error: null
|
||||
} as BookState;
|
||||
})
|
||||
);
|
||||
return this.fetchBooks(book => book.libraryId === libraryId);
|
||||
}
|
||||
|
||||
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(
|
||||
map(bookState => {
|
||||
if (bookState.books) {
|
||||
const filteredBooks = bookState.books.filter(book =>
|
||||
book.shelves?.some(shelf => shelf.id === shelfId)
|
||||
);
|
||||
return this.sortService.applySort(filteredBooks, this.selectedSort);
|
||||
if (bookState.loaded && !bookState.error) {
|
||||
const filteredBooks = bookState.books!.filter(book => {
|
||||
return bookFilter(book);
|
||||
});
|
||||
const sortedBooks = this.sortService.applySort(filteredBooks, this.selectedSort);
|
||||
return { ...bookState, books: sortedBooks };
|
||||
} else {
|
||||
return [];
|
||||
return bookState;
|
||||
}
|
||||
}),
|
||||
switchMap(books =>
|
||||
switchMap(bookState =>
|
||||
this.bookTitle$.pipe(
|
||||
map(title => {
|
||||
if (title && title.trim() !== '') {
|
||||
return books.filter(book =>
|
||||
book.metadata?.title?.toLowerCase().includes(title.toLowerCase())
|
||||
);
|
||||
const filteredBooks = bookState.books?.filter(book => book.metadata?.title?.toLowerCase().includes(title.toLowerCase())) || null;
|
||||
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;
|
||||
const routeParam$ = this.getRouteParams();
|
||||
this.bookState$ = routeParam$.pipe(
|
||||
switchMap(({libraryId, shelfId}) => this.fetchBooks(libraryId, shelfId))
|
||||
switchMap(({libraryId, shelfId}) => this.fetchBooksByEntity(libraryId, shelfId))
|
||||
);
|
||||
if (this.entityType === 'Library') {
|
||||
this.libraryService.updateSort(this.entity?.id!, sortOption).subscribe();
|
||||
|
||||
+16
-2
@@ -1,8 +1,21 @@
|
||||
<div class="dashboard-scroller-container">
|
||||
|
||||
<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 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"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
@@ -13,4 +26,5 @@
|
||||
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
+13
@@ -10,6 +10,18 @@
|
||||
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 {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -30,3 +42,4 @@
|
||||
scroll-snap-align: start;
|
||||
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 { InfiniteScrollDirective } from 'ngx-infinite-scroll';
|
||||
import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
|
||||
import {ProgressSpinnerModule} from 'primeng/progressspinner';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard-scroller',
|
||||
@@ -16,7 +17,8 @@ import { AsyncPipe, NgForOf, NgIf } from '@angular/common';
|
||||
NgForOf,
|
||||
NgIf,
|
||||
BookCardComponent,
|
||||
AsyncPipe
|
||||
AsyncPipe,
|
||||
ProgressSpinnerModule
|
||||
],
|
||||
})
|
||||
export class DashboardScrollerComponent implements OnInit {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="flex flex-column xxx">
|
||||
<div
|
||||
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">
|
||||
<p-button
|
||||
severity="secondary"
|
||||
|
||||
Reference in New Issue
Block a user