From 7f254f7c630b6d6aeeecdf03a5ad9690de1631fe Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Fri, 24 Jan 2025 13:34:09 -0700 Subject: [PATCH] - Improve dashboard scroller - Add random books in dashboard --- .../dashboard-scroller.component.html | 21 ++++---- .../dashboard-scroller.component.ts | 49 +++---------------- .../main-dashboard.component.html | 22 +++++++-- .../main-dashboard.component.ts | 25 +++++++--- .../metadata-fetch-options.component.ts | 4 +- 5 files changed, 54 insertions(+), 67 deletions(-) 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 b52f20fa6..a9a35f27b 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,30 +1,29 @@
-

{{ title }}

-
+

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

-
-

Failed to load books! :(

-
- -
- -
-
-
+ +
+
+ +
+ +
+

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 49a1c660a..5db15fc4b 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,13 +1,9 @@ -import {Component, ElementRef, inject, Input, OnInit, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs'; -import {map} from 'rxjs/operators'; -import {BookService} from '../../../book/service/book.service'; -import {BookState} from '../../../book/model/state/book-state.model'; +import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core'; import {BookCardComponent} from '../../../book/components/book-browser/book-card/book-card.component'; import {InfiniteScrollDirective} from 'ngx-infinite-scroll'; -import {AsyncPipe, NgForOf, NgIf} from '@angular/common'; +import {NgForOf, NgIf} from '@angular/common'; import {ProgressSpinnerModule} from 'primeng/progressspinner'; -import {Book} from 'epubjs'; +import {Book} from '../../../book/model/book.model'; @Component({ selector: 'app-dashboard-scroller', @@ -18,51 +14,18 @@ import {Book} from 'epubjs'; NgForOf, NgIf, BookCardComponent, - AsyncPipe, ProgressSpinnerModule ], }) export class DashboardScrollerComponent implements OnInit { - @Input() bookListType: 'lastRead' | 'latestAdded' = 'lastRead'; + @Input() bookListType: 'lastRead' | null = null; @Input() title: string = 'Last Read Books'; + @Input() books!: Book[] | null; + @ViewChild('scrollContainer') scrollContainer!: ElementRef; - bookState$: Observable | undefined; - - private bookService = inject(BookService); - @Input() books: Observable | undefined; ngOnInit(): void { - if (this.bookListType === 'lastRead') { - this.bookState$ = this.bookService.bookState$.pipe( - map((state: BookState) => ({ - ...state, - books: (state.books || []) - .filter(book => book.lastReadTime) - .sort((a, b) => { - const aTime = new Date(a.lastReadTime!).getTime(); - const bTime = new Date(b.lastReadTime!).getTime(); - return bTime - aTime; - }) - .slice(0, 25) - })) - ); - } - if (this.bookListType === 'latestAdded') { - this.bookState$ = this.bookService.bookState$.pipe( - map((state: BookState) => ({ - ...state, - books: (state.books || []) - .filter(book => book.addedOn) - .sort((a, b) => { - const aTime = new Date(a.addedOn!).getTime(); - const bTime = new Date(b.addedOn!).getTime(); - return bTime - aTime; - }) - .slice(0, 25) - })) - ); - } } } 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 606ac4eac..71bc1436d 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 @@ -1,6 +1,6 @@
-
+

Looks like you haven't added a library yet. Let's add one!

@@ -13,8 +13,24 @@
- - + + + + + + + + + + +
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 260effc9a..c1e12ecf6 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 @@ -10,6 +10,7 @@ import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroll import {BookService} from '../../../book/service/book.service'; import {BookState} from '../../../book/model/state/book-state.model'; import {Book} from '../../../book/model/book.model'; +import {LibraryState} from '../../../book/model/state/library-state.model'; @Component({ selector: 'app-main-dashboard', @@ -27,13 +28,17 @@ export class MainDashboardComponent implements OnInit { ref: DynamicDialogRef | undefined; private bookService = inject(BookService); + private libraryService = inject(LibraryService); private dialogService = inject(DialogService); lastReadBooks$: Observable | undefined; - latestAddedBooks$!: Observable; + latestAddedBooks$: Observable | undefined; + randomBooks$: Observable | undefined; + libraryState$: Observable | undefined = this.libraryService.libraryState$; ngOnInit(): void { this.bookService.loadBooks(); + this.lastReadBooks$ = this.bookService.bookState$.pipe( map((state: BookState) => ( (state.books || []).filter(book => book.lastReadTime) @@ -45,6 +50,7 @@ export class MainDashboardComponent implements OnInit { .slice(0, 25) )) ); + this.latestAddedBooks$ = this.bookService.bookState$.pipe( map((state: BookState) => ( (state.books || []) @@ -57,24 +63,29 @@ export class MainDashboardComponent implements OnInit { .slice(0, 25) )) ); + + this.randomBooks$ = this.bookService.bookState$.pipe( + map((state: BookState) => { + const books = state.books || []; + return this.getRandomBooks(books, 10); + }) + ); } - isLibrariesEmpty$: Observable = inject(LibraryService).libraryState$.pipe( - map(state => !state.libraries || state.libraries.length === 0) - ); + private getRandomBooks(books: Book[], count: number): Book[] { + const shuffled = books.sort(() => 0.5 - Math.random()); + return shuffled.slice(0, count); + } createNewLibrary() { this.ref = this.dialogService.open(LibraryCreatorComponent, { header: 'Create New Library', modal: true, closable: true, - width: '675px', - height: '480px', style: { position: 'absolute', top: '15%', } }); } - } diff --git a/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component.ts b/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component.ts index ff983bd04..8eafe041b 100644 --- a/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component.ts +++ b/booklore-ui/src/app/metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component.ts @@ -1,7 +1,6 @@ import {Component, inject} from '@angular/core'; import {DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog'; import {MetadataAdvancedFetchOptionsComponent} from '../metadata-advanced-fetch-options/metadata-advanced-fetch-options.component'; -import {Divider} from 'primeng/divider'; import {MetadataService} from '../../service/metadata.service'; import {MetadataRefreshRequest} from '../../model/request/metadata-refresh-request.model'; import {MetadataRefreshType} from '../../model/request/metadata-refresh-type.enum'; @@ -12,8 +11,7 @@ import {MetadataRefreshOptions} from '../../model/request/metadata-refresh-optio standalone: true, templateUrl: './metadata-fetch-options.component.html', imports: [ - MetadataAdvancedFetchOptionsComponent, - Divider + MetadataAdvancedFetchOptionsComponent ], styleUrl: './metadata-fetch-options.component.scss' })