WIP: Rearrange code

This commit is contained in:
aditya.chandel
2025-01-12 13:38:57 -07:00
parent 7df0052036
commit ef3556cb0c
77 changed files with 101 additions and 115 deletions
@@ -0,0 +1,30 @@
<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">
<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">
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
</div>
</div>
</div>
@@ -0,0 +1,45 @@
.dashboard-scroller-container {
margin-bottom: 20px;
}
.dashboard-scroller-title {
font-size: 1.5rem;
color: var(--text-color);
margin-bottom: 10px;
padding: 5px;
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;
overflow-x: auto;
overflow-y: hidden;
scroll-snap-type: x mandatory;
padding: 5px;
gap: 20px;
height: 100%;
box-sizing: border-box;
}
.infinite-scroller-a-book {
overflow: hidden;
background-color: var(--card-background);
border-radius: 8px;
flex: 0 0 9.5%;
scroll-snap-align: start;
position: relative;
}
@@ -0,0 +1,59 @@
import { Component, ElementRef, 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 { 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 {ProgressSpinnerModule} from 'primeng/progressspinner';
@Component({
selector: 'app-dashboard-scroller',
templateUrl: './dashboard-scroller.component.html',
styleUrls: ['./dashboard-scroller.component.scss'],
imports: [
InfiniteScrollDirective,
NgForOf,
NgIf,
BookCardComponent,
AsyncPipe,
ProgressSpinnerModule
],
})
export class DashboardScrollerComponent implements OnInit {
@Input() bookListType: 'lastRead' | 'latestAdded' = 'lastRead';
@Input() title: string = 'Last Read Books';
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
bookState$: Observable<BookState> | undefined;
constructor(private bookService: BookService) {}
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) => new Date(b.lastReadTime!).getTime() - new Date(a.lastReadTime!).getTime())
.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) => new Date(b.addedOn!).getTime() - new Date(a.addedOn!).getTime())
.slice(0, 25)
}))
);
}
}
}