Try fixing dashboard spinner
This commit is contained in:
+7
-6
@@ -1,12 +1,17 @@
|
||||
<p class="dashboard-scroller-title">{{ title }}</p>
|
||||
|
||||
<div class="dashboard-scroller-no-books" *ngIf="!books || books.length === 0">
|
||||
<div *ngIf="isLoading">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-scroller-no-books" *ngIf="!isLoading && (!books || books.length === 0)">
|
||||
<p class="text-sm">
|
||||
{{ bookListType === 'lastRead' ? "You haven't read any books yet!" : "No books have been added to BookLore!" }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-scroller-infinite"
|
||||
*ngIf="!isLoading && books"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
@@ -19,10 +24,6 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div *ngIf="!books">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<div *ngIf="books === null">
|
||||
<div *ngIf="!isLoading && books === null">
|
||||
<p class="text-sm">Failed to load books! :(</p>
|
||||
</div>
|
||||
|
||||
+13
-2
@@ -1,4 +1,4 @@
|
||||
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
|
||||
import {Component, ElementRef, Input, OnChanges, OnInit, ViewChild} from '@angular/core';
|
||||
import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
@@ -18,7 +18,7 @@ import {Book} from '../../../book/model/book.model';
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class DashboardScrollerComponent implements OnInit {
|
||||
export class DashboardScrollerComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input() bookListType: 'lastRead' | null = null;
|
||||
@Input() title: string = 'Last Read Books';
|
||||
@@ -27,6 +27,17 @@ export class DashboardScrollerComponent implements OnInit {
|
||||
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
||||
|
||||
|
||||
isLoading = true;
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.books !== undefined) {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(): void {
|
||||
if (this.books !== undefined) {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@
|
||||
</div>
|
||||
|
||||
<app-dashboard-scroller
|
||||
[books]="randomBooks"
|
||||
[books]="randomBooks$ | async"
|
||||
[title]="'Discover Random Reads'">
|
||||
</app-dashboard-scroller>
|
||||
|
||||
|
||||
+4
-11
@@ -34,7 +34,7 @@ export class MainDashboardComponent implements OnInit {
|
||||
|
||||
lastReadBooks$: Observable<Book[]> | undefined;
|
||||
latestAddedBooks$: Observable<Book[]> | undefined;
|
||||
randomBooks!: Book[];
|
||||
randomBooks$: Observable<Book[]> | undefined;
|
||||
|
||||
isLibrariesEmpty$: Observable<boolean> = inject(LibraryService).libraryState$.pipe(
|
||||
map(state => !state.libraries || state.libraries.length === 0)
|
||||
@@ -68,16 +68,9 @@ export class MainDashboardComponent implements OnInit {
|
||||
))
|
||||
);
|
||||
|
||||
this.bookService.bookState$.pipe(
|
||||
filter((state): state is BookState => !!state && !!state.books && state.books.length > 0),
|
||||
take(1),
|
||||
map((state) => {
|
||||
const books = state.books || [];
|
||||
return this.getRandomBooks(books, 15);
|
||||
})
|
||||
).subscribe((randomBooks) => {
|
||||
this.randomBooks = randomBooks;
|
||||
});
|
||||
this.randomBooks$ = this.bookService.bookState$.pipe(
|
||||
map((state: BookState) => this.getRandomBooks(state.books || [], 15))
|
||||
);
|
||||
}
|
||||
|
||||
private getRandomBooks(books: Book[], count: number): Book[] {
|
||||
|
||||
Reference in New Issue
Block a user