- Improve dashboard scroller
- Add random books in dashboard
This commit is contained in:
+10
-11
@@ -1,30 +1,29 @@
|
||||
<div class="dashboard-scroller-container">
|
||||
|
||||
<h2 class="dashboard-scroller-title">{{ title }}</h2>
|
||||
|
||||
<div class="no-books-container" *ngIf="!(bookState$ | async)?.error && (bookState$ | async)?.loaded && (bookState$ | async)?.books?.length === 0">
|
||||
<div class="no-books-container" *ngIf="!books || 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"
|
||||
[infiniteScrollThrottle]="50"
|
||||
#scrollContainer
|
||||
[horizontal]="true">
|
||||
<div class="infinite-scroller-a-book" *ngFor="let book of (bookState$ | async)?.books">
|
||||
|
||||
<div class="infinite-scroller-a-book" *ngFor="let book of books">
|
||||
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!books || books.length === 0">
|
||||
<p-progressSpinner></p-progressSpinner>
|
||||
</div>
|
||||
|
||||
<div *ngIf="books === null">
|
||||
<p class="no-books-text">Failed to load books! :(</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+6
-43
@@ -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<BookState> | undefined;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
@Input() books: Observable<Book[]> | 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)
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-3
@@ -1,6 +1,6 @@
|
||||
<div class="dashboard">
|
||||
|
||||
<div class="dashboard-no-library" *ngIf="isLibrariesEmpty$ | async; else dashboardScroller">
|
||||
<div class="dashboard-no-library" *ngIf="libraryState$ | async; else dashboardScroller">
|
||||
<h1 class="no-library-header">
|
||||
Looks like you haven't added a library yet. Let's add one!
|
||||
</h1>
|
||||
@@ -13,8 +13,24 @@
|
||||
</div>
|
||||
|
||||
<ng-template #dashboardScroller>
|
||||
<app-dashboard-scroller [bookListType]="'lastRead'" [books]="lastReadBooks$ || []" title="Last Read Books"></app-dashboard-scroller>
|
||||
<app-dashboard-scroller [bookListType]="'latestAdded'" title="Latest Added Books"></app-dashboard-scroller>
|
||||
|
||||
<app-dashboard-scroller
|
||||
[books]="lastReadBooks$ | async"
|
||||
[bookListType]="'lastRead'"
|
||||
[title]="'Last Read Books'">
|
||||
</app-dashboard-scroller>
|
||||
|
||||
<app-dashboard-scroller
|
||||
[books]="latestAddedBooks$ | async"
|
||||
[title]="'Latest Added Books'">
|
||||
</app-dashboard-scroller>
|
||||
|
||||
<app-dashboard-scroller
|
||||
[books]="randomBooks$ | async"
|
||||
[title]="'Some Random Books'">
|
||||
</app-dashboard-scroller>
|
||||
|
||||
|
||||
</ng-template>
|
||||
|
||||
</div>
|
||||
|
||||
+18
-7
@@ -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<Book[]> | undefined;
|
||||
latestAddedBooks$!: Observable<Book[]>;
|
||||
latestAddedBooks$: Observable<Book[]> | undefined;
|
||||
randomBooks$: Observable<Book[]> | undefined;
|
||||
libraryState$: Observable<LibraryState> | 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<boolean> = 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%',
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -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'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user