Added late read module
This commit is contained in:
@@ -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