Added late read module
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
<div class="book-list-container">
|
||||
<h2 class="last-read-title">Last Read</h2>
|
||||
<div class="book-list"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
(scrolled)="loadMore()"
|
||||
#scrollContainer
|
||||
(scroll)="onScroll($event)">
|
||||
<div class="book-item" *ngFor="let book of books">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover" alt="Cover of {{ book.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
<h4>{{ book.title }}</h4>
|
||||
<p>{{ getAuthorNames(book) }}</p>
|
||||
<p-button label="View" icon="pi pi-eye" class="view-btn" (click)="openBook(book.id)"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
.book-list-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.last-read-title {
|
||||
font-size: 1.5rem;
|
||||
color: var(--text-color);
|
||||
margin-bottom: 10px;
|
||||
padding: 5px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.book-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 10px;
|
||||
gap: 20px;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.book-item {
|
||||
overflow: hidden;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 8px;
|
||||
flex: 0 0 12%;
|
||||
scroll-snap-align: start;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
height: 225px;
|
||||
object-fit: cover;
|
||||
background-color: #444;
|
||||
transition: background-color 0.3s ease, filter 0.3s ease;
|
||||
position: relative;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.book-item:hover .book-cover {
|
||||
filter: blur(2px);
|
||||
}
|
||||
|
||||
.book-info {
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 0.9rem;
|
||||
color: var(--text-color);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 100%;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
p {
|
||||
color: var(--text-color-secondary);
|
||||
font-size: 0.7rem;
|
||||
line-height: 1.2;
|
||||
margin: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.view-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: none;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.book-item:hover .view-btn {
|
||||
display: block;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
|
||||
import { Book } from '../../model/book.model';
|
||||
import { BookService } from '../../service/book.service';
|
||||
import { Button } from 'primeng/button';
|
||||
import { InfiniteScrollDirective } from 'ngx-infinite-scroll';
|
||||
import { NgForOf } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard-scroller',
|
||||
templateUrl: './dashboard-scroller.component.html',
|
||||
imports: [
|
||||
Button,
|
||||
InfiniteScrollDirective,
|
||||
NgForOf
|
||||
],
|
||||
styleUrls: ['./dashboard-scroller.component.scss']
|
||||
})
|
||||
export class DashboardScrollerComponent implements OnInit {
|
||||
books: Book[] = [];
|
||||
private currentPage: number = 0;
|
||||
|
||||
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
||||
|
||||
constructor(private bookService: BookService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadBooks();
|
||||
}
|
||||
|
||||
loadBooks(): void {
|
||||
this.bookService.loadLatestBooks(this.currentPage).subscribe({
|
||||
next: (response) => {
|
||||
this.books = [...this.books, ...response.content];
|
||||
this.currentPage++;
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error loading books:', err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
coverImageSrc(bookId: number): string {
|
||||
return this.bookService.getBookCoverUrl(bookId);
|
||||
}
|
||||
|
||||
loadMore(): void {
|
||||
console.log('Loading more books...');
|
||||
this.loadBooks();
|
||||
}
|
||||
|
||||
getAuthorNames(book: Book): string {
|
||||
return book.authors?.map((author) => author.name).join(', ') || 'No authors available';
|
||||
}
|
||||
|
||||
openBook(bookId: number): void {
|
||||
const url = `/pdf-viewer/book/${bookId}`;
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
|
||||
onScroll(event: any): void {
|
||||
const container = this.scrollContainer.nativeElement;
|
||||
const scrollRight = container.scrollWidth - container.scrollLeft === container.clientWidth;
|
||||
if (scrollRight) {
|
||||
this.loadMore();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user