Added late read module
This commit is contained in:
@@ -17,9 +17,9 @@ import {InputIconModule} from 'primeng/inputicon';
|
||||
import {ToggleButtonModule} from 'primeng/togglebutton';
|
||||
import {PasswordModule} from 'primeng/password';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import { LibraryBrowserComponent } from './book/component/library-browser/library-browser.component';
|
||||
import {LibraryBrowserComponent} from './book/component/library-browser/library-browser.component';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import { SearchComponent } from './book/component/search/search.component';
|
||||
import {SearchComponent} from './book/component/search/search.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
||||
+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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
<div class="dashboard">
|
||||
<h1 *ngIf="isLibrariesEmpty" class="no-library-header">
|
||||
Looks like you haven't added a library yet. Let's add one!
|
||||
</h1>
|
||||
<p-button *ngIf="isLibrariesEmpty"
|
||||
label="Add a Library"
|
||||
icon="pi pi-plus"
|
||||
styleClass="p-button-rounded p-button-outlined"
|
||||
(click)="createNewLibrary($event)">
|
||||
</p-button>
|
||||
<div *ngIf="isLibrariesEmpty; else dashboardScroller">
|
||||
<h1 class="no-library-header">
|
||||
Looks like you haven't added a library yet. Let's add one!
|
||||
</h1>
|
||||
<p-button
|
||||
label="Add a Library"
|
||||
icon="pi pi-plus"
|
||||
styleClass="p-button-rounded p-button-outlined"
|
||||
(click)="createNewLibrary($event)">
|
||||
</p-button>
|
||||
</div>
|
||||
|
||||
<ng-template #dashboardScroller>
|
||||
<app-dashboard-scroller></app-dashboard-scroller>
|
||||
</ng-template>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
.dashboard {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.no-library-header {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--text-color)
|
||||
}
|
||||
.p-dialog {
|
||||
max-width: 90%; /* Ensure the dialog doesn't overflow the viewport */
|
||||
}
|
||||
.dashboard .no-library-header {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.dashboard .p-dialog {
|
||||
max-width: 90%;
|
||||
}
|
||||
|
||||
::ng-deep .p-dialog-mask {
|
||||
background-color: rgba(0, 0, 0, 0.5); /* Darken the background with 50% opacity */
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
/* You can also adjust the blur if you want */
|
||||
::ng-deep .p-dialog-mask {
|
||||
backdrop-filter: blur(3px); /* Optional: Apply blur to the background */
|
||||
backdrop-filter: blur(3px);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,18 @@ import { Button } from 'primeng/button';
|
||||
import { NgIf } from '@angular/common';
|
||||
import { LibraryCreatorComponent } from '../library-creator/library-creator.component';
|
||||
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
||||
import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroller.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home-page',
|
||||
templateUrl: './dashboard.component.html',
|
||||
imports: [
|
||||
Button,
|
||||
NgIf
|
||||
NgIf,
|
||||
DashboardScrollerComponent
|
||||
],
|
||||
styleUrls: ['./dashboard.component.scss'],
|
||||
providers: [DialogService], // Ensure the DialogService is available
|
||||
providers: [DialogService],
|
||||
})
|
||||
export class DashboardComponent {
|
||||
private libraries: WritableSignal<Library[]>;
|
||||
@@ -25,7 +27,7 @@ export class DashboardComponent {
|
||||
}
|
||||
|
||||
get isLibrariesEmpty(): boolean {
|
||||
return this.libraries()?.length === 1;
|
||||
return this.libraries()?.length === 0;
|
||||
}
|
||||
|
||||
createNewLibrary(event: MouseEvent) {
|
||||
@@ -39,12 +41,12 @@ export class DashboardComponent {
|
||||
|
||||
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||
modal: true,
|
||||
width: `${dialogWidthPercentage}%`, // Dynamic width
|
||||
height: 'auto', // Let height adapt to content
|
||||
width: `${dialogWidthPercentage}%`,
|
||||
height: 'auto',
|
||||
style: {
|
||||
position: 'absolute',
|
||||
top: `${buttonRect.bottom + 10}px`, // Position below the button
|
||||
left: `${Math.max(leftPosition, 0)}px`, // Ensure it stays within the viewport
|
||||
top: `${buttonRect.bottom + 10}px`,
|
||||
left: `${Math.max(leftPosition, 0)}px`
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<div class="book-list" infiniteScroll [infiniteScrollDistance]="2" [infiniteScrollThrottle]="50" (scrolled)="loadMore()">
|
||||
<div class="book-list"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]=true
|
||||
(scrolled)="loadMore()">
|
||||
<div class="book-item" *ngFor="let book of books">
|
||||
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.title }}" loading="lazy"/>
|
||||
<div class="book-info">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectorRef, Component, NgZone, OnInit } from '@angular/core';
|
||||
import { ChangeDetectorRef, Component, NgZone, OnInit, OnDestroy } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { NgxExtendedPdfViewerModule, ScrollModeType } from 'ngx-extended-pdf-viewer';
|
||||
import { BookService } from '../../service/book.service';
|
||||
@@ -9,7 +9,7 @@ import { BookService } from '../../service/book.service';
|
||||
imports: [NgxExtendedPdfViewerModule],
|
||||
templateUrl: './pdf-viewer.component.html',
|
||||
})
|
||||
export class PdfViewerComponent implements OnInit {
|
||||
export class PdfViewerComponent implements OnInit, OnDestroy {
|
||||
bookId!: number;
|
||||
handTool = true;
|
||||
page = 1;
|
||||
@@ -31,18 +31,25 @@ export class PdfViewerComponent implements OnInit {
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
this.bookId = +params.get('bookId')!;
|
||||
this.loadBook(this.bookId);
|
||||
this.updateLastReadTime();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.updateLastReadTime();
|
||||
}
|
||||
|
||||
private loadBook(bookId: number): void {
|
||||
this.bookService.getBook(bookId).subscribe((book) => {
|
||||
this.zone.run(() => {
|
||||
const { pageNumber, zoom, sidebar_visible, spread } = book.viewerSetting;
|
||||
this.page = pageNumber || 1;
|
||||
this.zoom = zoom || 'page-fit';
|
||||
this.sidebarVisible = sidebar_visible || false;
|
||||
this.spread = spread || 'odd';
|
||||
this.isInitialLoad = false;
|
||||
this.bookService.getBookSetting(bookId).subscribe((bookSetting) => {
|
||||
const { pageNumber, zoom, sidebar_visible, spread } = bookSetting;
|
||||
this.page = pageNumber || 1;
|
||||
this.zoom = zoom || 'page-fit';
|
||||
this.sidebarVisible = sidebar_visible || false;
|
||||
this.spread = spread || 'odd';
|
||||
this.isInitialLoad = false;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -58,7 +65,12 @@ export class PdfViewerComponent implements OnInit {
|
||||
this.bookService.updateViewerSetting(updatedViewerSetting, this.bookId).subscribe();
|
||||
}
|
||||
|
||||
private updateLastReadTime(): void {
|
||||
this.bookService.updateLastReadTime(this.bookId).subscribe();
|
||||
}
|
||||
|
||||
onPageChange(page: number): void {
|
||||
console.log('page', page);
|
||||
if (page !== this.page) {
|
||||
this.page = page;
|
||||
this.updateViewerSetting();
|
||||
@@ -66,6 +78,7 @@ export class PdfViewerComponent implements OnInit {
|
||||
}
|
||||
|
||||
onZoomChange(zoom: string | number): void {
|
||||
console.log('zoom', zoom);
|
||||
if (zoom !== this.zoom) {
|
||||
this.zoom = zoom;
|
||||
this.updateViewerSetting();
|
||||
@@ -73,6 +86,7 @@ export class PdfViewerComponent implements OnInit {
|
||||
}
|
||||
|
||||
onSidebarVisibleChange(visible: boolean): void {
|
||||
console.log('sidebarVisible', visible);
|
||||
if (visible !== this.sidebarVisible) {
|
||||
this.sidebarVisible = visible;
|
||||
this.updateViewerSetting();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface BookSetting {
|
||||
pageNumber: number;
|
||||
zoom: number | string;
|
||||
sidebar_visible: boolean;
|
||||
spread: 'off' | 'even' | 'odd';
|
||||
}
|
||||
@@ -5,14 +5,6 @@ export interface Book {
|
||||
libraryId: number;
|
||||
title: string;
|
||||
authors: Author[];
|
||||
viewerSetting: BookViewerSetting;
|
||||
}
|
||||
|
||||
export interface BookViewerSetting {
|
||||
pageNumber: number;
|
||||
zoom: number | string;
|
||||
sidebar_visible: boolean;
|
||||
spread: 'off' | 'even' | 'odd';
|
||||
}
|
||||
|
||||
export interface PaginatedBooksResponse {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Observable } from 'rxjs';
|
||||
import { Book, PaginatedBooksResponse } from '../model/book.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {BookSetting} from '../model/book-settings.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -23,6 +24,12 @@ export class BookService {
|
||||
);
|
||||
}
|
||||
|
||||
loadLatestBooks(page: number): Observable<PaginatedBooksResponse> {
|
||||
return this.http.get<PaginatedBooksResponse>(
|
||||
`${this.bookUrl}?page=${page}&size=10&sortBy=lastReadTime&sortDir=desc`
|
||||
);
|
||||
}
|
||||
|
||||
searchBooks(query: string): Observable<Book[]> {
|
||||
if (query.length < 3) {
|
||||
return new Observable<Book[]>();
|
||||
@@ -35,6 +42,10 @@ export class BookService {
|
||||
return this.http.put<void>(url, viewerSetting);
|
||||
}
|
||||
|
||||
getBookSetting(bookId: number): Observable<BookSetting> {
|
||||
return this.http.get<BookSetting>(`${this.bookUrl}/${bookId}/viewer-setting`);
|
||||
}
|
||||
|
||||
getBookDataUrl(bookId: number): string {
|
||||
return `${this.bookUrl}/${bookId}/data`;
|
||||
}
|
||||
@@ -42,4 +53,8 @@ export class BookService {
|
||||
getBookCoverUrl(bookId: number): string {
|
||||
return `${this.bookUrl}/${bookId}/cover`;
|
||||
}
|
||||
|
||||
updateLastReadTime(bookId: number): Observable<void> {
|
||||
return this.http.put<void>(`${this.bookUrl}/${bookId}/update-last-read`, {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user