diff --git a/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.html b/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.html index 89f8c6ca2..8f236bdf1 100644 --- a/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.html +++ b/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.html @@ -1,12 +1,17 @@

{{ title }}

-
+
+ +
+ +

{{ bookListType === 'lastRead' ? "You haven't read any books yet!" : "No books have been added to BookLore!" }}

-
- -
- -
+

Failed to load books! :(

diff --git a/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts b/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts index 92dab0db9..513b17399 100644 --- a/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts +++ b/booklore-ui/src/app/dashboard/components/dashboard-scroller/dashboard-scroller.component.ts @@ -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; + } } } diff --git a/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html b/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html index badc443dc..16bf28beb 100644 --- a/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html +++ b/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.html @@ -34,7 +34,7 @@
diff --git a/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.ts b/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.ts index 5e182e396..e2677c0de 100644 --- a/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.ts +++ b/booklore-ui/src/app/dashboard/components/main-dashboard/main-dashboard.component.ts @@ -34,7 +34,7 @@ export class MainDashboardComponent implements OnInit { lastReadBooks$: Observable | undefined; latestAddedBooks$: Observable | undefined; - randomBooks!: Book[]; + randomBooks$: Observable | undefined; isLibrariesEmpty$: Observable = 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[] {