From 788dc9796e7cedac97f93077df37ebe69a0c20f7 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Wed, 22 Jan 2025 22:13:48 -0700 Subject: [PATCH] Actual fix --- .../pdf-viewer/pdf-viewer.component.ts | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts b/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts index 80f53988d..1c3726ac9 100644 --- a/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts +++ b/booklore-ui/src/app/book/components/pdf-viewer/pdf-viewer.component.ts @@ -39,6 +39,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy { ngOnInit(): void { this.route.paramMap.subscribe((params) => { this.bookId = +params.get('bookId')!; + this.appSettingsService.appSettings$ .pipe( filter((appSettings) => appSettings !== null), @@ -48,6 +49,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy { const book$ = this.bookService.getBookByIdFromAPI(this.bookId, false); const pdf$ = this.bookService.getPdfData(this.bookId); const bookSetting$ = this.bookService.getBookSetting(this.bookId); + forkJoin([book$, pdf$, bookSetting$]).subscribe((results) => { const pdf = results[0]; const pdfData = results[1]; @@ -61,20 +63,6 @@ export class PdfViewerComponent implements OnInit, OnDestroy { }); } - onPdfLoaded($event: PdfLoadedEvent) { - this.pdfLoaded = true; - this.updateProgress(); - if (this.pdfScope === 'global') { - this.zoom = this.globalPdfSettings?.zoom || 'page-fit'; - this.sidebarVisible = this.globalPdfSettings?.sidebar ?? true; - this.spread = this.globalPdfSettings?.spread || 'odd'; - } else { - this.zoom = this.individualPdfSettings?.zoom || this.globalPdfSettings?.zoom || 'page-fit'; - this.sidebarVisible = this.individualPdfSettings?.sidebarVisible ?? this.globalPdfSettings?.sidebar ?? true; - this.spread = this.individualPdfSettings?.spread || this.globalPdfSettings?.spread || 'odd'; - } - } - onPageChange(page: number): void { if (!this.pdfLoaded) return; if (page !== this.page) { @@ -84,6 +72,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy { } onZoomChange(zoom: string | number): void { + if (!this.pdfLoaded) return; if (zoom !== this.zoom) { this.zoom = zoom; this.updateViewerSetting(); @@ -91,6 +80,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy { } onSidebarVisibleChange(visible: boolean): void { + if (!this.pdfLoaded) return; if (visible !== this.sidebarVisible) { this.sidebarVisible = visible; this.updateViewerSetting(); @@ -98,6 +88,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy { } onSpreadChange(spread: 'off' | 'even' | 'odd'): void { + if (!this.pdfLoaded) return; if (spread !== this.spread) { this.spread = spread; this.updateViewerSetting(); @@ -105,6 +96,7 @@ export class PdfViewerComponent implements OnInit, OnDestroy { } private updateViewerSetting(): void { + if (!this.pdfLoaded) return; const bookSetting: BookSetting = { pdfSettings: { sidebarVisible: this.sidebarVisible, @@ -125,4 +117,18 @@ export class PdfViewerComponent implements OnInit, OnDestroy { } this.updateProgress(); } + + onPdfLoaded($event: PdfLoadedEvent) { + this.pdfLoaded = true; + this.updateProgress(); + if (this.pdfScope === 'global') { + this.zoom = this.globalPdfSettings?.zoom || 'page-fit'; + this.sidebarVisible = this.globalPdfSettings?.sidebar ?? true; + this.spread = this.globalPdfSettings?.spread || 'odd'; + } else { + this.zoom = this.individualPdfSettings?.zoom || this.globalPdfSettings?.zoom || 'page-fit'; + this.sidebarVisible = this.individualPdfSettings?.sidebarVisible ?? this.globalPdfSettings?.sidebar ?? true; + this.spread = this.individualPdfSettings?.spread || this.globalPdfSettings?.spread || 'odd'; + } + } }