Merge branch 'develop' of github.com:adityachandelgit/BookLore into develop

This commit is contained in:
aditya.chandel
2025-03-28 02:33:26 -06:00
4 changed files with 127 additions and 95 deletions
@@ -1,5 +1,6 @@
<div class="epub-viewer-container">
<div #epubContainer class="epub-viewer-container">
<p-progressSpinner *ngIf="isLoading"></p-progressSpinner>
<div *ngIf="!isLoading">
<p-button class="menu-toggle-button" (click)="toggleDrawer()" icon="pi pi-bars" severity="secondary"></p-button>
<p-drawer [(visible)]="isDrawerVisible" [modal]="false" [position]="'left'" header="Chapters">
<ul class="chapter-list">
@@ -32,4 +33,5 @@
<button class="epub-controls-left" (click)="prevPage()" >←</button>
<button class="epub-controls-right" (click)="nextPage()">→</button>
</div>
</div>
@@ -2,16 +2,17 @@ import {Component, ElementRef, inject, OnDestroy, OnInit, ViewChild} from '@angu
import ePub from 'epubjs';
import {Drawer} from 'primeng/drawer';
import {Button} from 'primeng/button';
import {NgForOf} from '@angular/common';
import {NgForOf, NgIf} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {Divider} from 'primeng/divider';
import {ActivatedRoute} from '@angular/router';
import {Book, BookSetting} from '../../../model/book.model';
import {BookService} from '../../../service/book.service';
import {filter, forkJoin, take} from 'rxjs';
import {AppSettingsService} from '../../../../core/service/app-settings.service';
import {forkJoin} from 'rxjs';
import {Select} from 'primeng/select';
import {UserService} from '../../../../user.service';
import {ProgressSpinner} from 'primeng/progressspinner';
import {MessageService} from 'primeng/api';
const FALLBACK_EPUB_SETTINGS = {
fontSize: 150,
@@ -25,12 +26,13 @@ const FALLBACK_EPUB_SETTINGS = {
selector: 'app-epub-viewer',
templateUrl: './epub-viewer.component.html',
styleUrls: ['./epub-viewer.component.scss'],
imports: [Drawer, Button, NgForOf, FormsModule, Divider, Select],
imports: [Drawer, Button, NgForOf, FormsModule, Divider, Select, ProgressSpinner, NgIf],
standalone: true
})
export class EpubViewerComponent implements OnInit, OnDestroy {
@ViewChild('epubContainer', {static: true}) epubContainer!: ElementRef;
@ViewChild('epubContainer', {static: false}) epubContainer!: ElementRef;
isLoading = true;
chapters: { label: string; href: string }[] = [];
isDrawerVisible = false;
isSettingsDrawerVisible = false;
@@ -61,11 +63,13 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
private route = inject(ActivatedRoute);
private userService = inject(UserService);
private bookService = inject(BookService);
private messageService = inject(MessageService);
epub!: Book;
ngOnInit(): void {
this.route.paramMap.subscribe((params) => {
this.isLoading = true;
const bookId = +params.get('bookId')!;
const myself$ = this.userService.getMyself();
@@ -73,7 +77,8 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
const epubData$ = this.bookService.getFileContent(bookId);
const bookSetting$ = this.bookService.getBookSetting(bookId);
forkJoin([myself$, epub$, epubData$, bookSetting$]).subscribe((results) => {
forkJoin([myself$, epub$, epubData$, bookSetting$]).subscribe({
next: (results) => {
const myself = results[0];
const epub = results[1];
const epubData = results[2];
@@ -126,9 +131,15 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
this.setupKeyListener();
this.trackProgress();
this.isLoading = false;
};
fileReader.readAsArrayBuffer(epubData);
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load the book'});
this.isLoading = false;
}
});
});
}
@@ -1,4 +1,9 @@
<div *ngIf="isLoading" class="flex justify-center items-center h-screen relative">
<p-progressSpinner></p-progressSpinner>
</div>
<ngx-extended-pdf-viewer
*ngIf="!isLoading"
[src]="bookData"
[handTool]="handTool"
[height]="'auto'"
@@ -7,14 +7,19 @@ import {filter, forkJoin, Subscription, take} from 'rxjs';
import {BookSetting, PdfViewerSetting} from '../../model/book.model';
import {PdfSettings} from '../../../core/model/app-settings.model';
import {UserService} from '../../../user.service';
import {NgIf} from '@angular/common';
import {ProgressSpinner} from 'primeng/progressspinner';
import {MessageService} from 'primeng/api';
@Component({
selector: 'app-pdf-viewer',
standalone: true,
imports: [NgxExtendedPdfViewerModule],
imports: [NgxExtendedPdfViewerModule, NgIf, ProgressSpinner],
templateUrl: './pdf-viewer.component.html',
})
export class PdfViewerComponent implements OnInit, OnDestroy {
isLoading = true;
handTool = true;
rotation: 0 | 90 | 180 | 270 = 0;
@@ -28,10 +33,12 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
private bookService = inject(BookService);
private userService = inject(UserService);
private messageService = inject(MessageService);
private route = inject(ActivatedRoute);
ngOnInit(): void {
this.route.paramMap.subscribe((params) => {
this.isLoading = true;
this.bookId = +params.get('bookId')!;
const myself$ = this.userService.getMyself();
@@ -39,7 +46,8 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
const bookSetting$ = this.bookService.getBookSetting(this.bookId);
const pdfData$ = this.bookService.getFileContent(this.bookId);
forkJoin([book$, bookSetting$, pdfData$, myself$]).subscribe((results) => {
forkJoin([book$, bookSetting$, pdfData$, myself$]).subscribe({
next: (results) => {
const pdfMeta = results[0];
const pdfPrefs = results[1];
const pdfData = results[2];
@@ -55,6 +63,12 @@ export class PdfViewerComponent implements OnInit, OnDestroy {
}
this.page = pdfMeta.pdfProgress || 1;
this.bookData = pdfData;
this.isLoading = false;
},
error: () => {
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load the book'});
this.isLoading = false;
}
});
});
}