feat: implement loaders for EPUB and PDF readers (#38)
This commit is contained in:
committed by
Aditya Chandel
parent
fac3f8c819
commit
6a4b6b2bcb
@@ -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,22 +46,29 @@ 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) => {
|
||||
const pdfMeta = results[0];
|
||||
const pdfPrefs = results[1];
|
||||
const pdfData = results[2];
|
||||
const myself = results[3];
|
||||
forkJoin([book$, bookSetting$, pdfData$, myself$]).subscribe({
|
||||
next: (results) => {
|
||||
const pdfMeta = results[0];
|
||||
const pdfPrefs = results[1];
|
||||
const pdfData = results[2];
|
||||
const myself = results[3];
|
||||
|
||||
let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf;
|
||||
if (globalOrIndividual === 'Global') {
|
||||
this.zoom = myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.spread = myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
|
||||
} else {
|
||||
this.zoom = pdfPrefs.pdfSettings?.zoom || myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.spread = pdfPrefs.pdfSettings?.spread || myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
|
||||
let globalOrIndividual = myself.bookPreferences.perBookSetting.pdf;
|
||||
if (globalOrIndividual === 'Global') {
|
||||
this.zoom = myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.spread = myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
|
||||
} else {
|
||||
this.zoom = pdfPrefs.pdfSettings?.zoom || myself.bookPreferences.pdfReaderSetting.pageZoom || 'page-fit';
|
||||
this.spread = pdfPrefs.pdfSettings?.spread || myself.bookPreferences.pdfReaderSetting.pageSpread || 'odd';
|
||||
}
|
||||
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;
|
||||
}
|
||||
this.page = pdfMeta.pdfProgress || 1;
|
||||
this.bookData = pdfData;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user