From 1348da2d345b080002a62a24d717fac15c4b0a92 Mon Sep 17 00:00:00 2001 From: b0ink <40929320+b0ink@users.noreply.github.com> Date: Mon, 5 Aug 2024 21:22:03 +1000 Subject: [PATCH] feat: persistent pdf zoom level --- src/app/common/pdf-viewer/pdf-viewer.component.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/common/pdf-viewer/pdf-viewer.component.ts b/src/app/common/pdf-viewer/pdf-viewer.component.ts index 8f21f8e47..17f6d85fb 100644 --- a/src/app/common/pdf-viewer/pdf-viewer.component.ts +++ b/src/app/common/pdf-viewer/pdf-viewer.component.ts @@ -19,6 +19,9 @@ import {AlertService} from '../services/alert.service'; styleUrls: ['./pdf-viewer.component.scss'], }) export class fPdfViewerComponent implements OnDestroy, OnChanges, AfterViewInit { + private readonly ZOOM_MIN = 0.5; + private readonly ZOOM_MAX = 2.5; + private _pdfUrl: string; public pdfBlobUrl: string; public useNativePdfViewer = false; @@ -43,6 +46,9 @@ export class fPdfViewerComponent implements OnDestroy, OnChanges, AfterViewInit ngAfterViewInit(): void { this.useNativePdfViewer = localStorage.getItem('useNativePdfViewer') === 'true'; + const storedZoomValue = parseFloat(localStorage.getItem('pdfViewerZoom')) || 1; + // Clamp zoom value between ZOOM_MIN and ZOOM_MAX + this.zoomValue = Math.min(Math.max(storedZoomValue, this.ZOOM_MIN), this.ZOOM_MAX); } ngOnChanges(changes: SimpleChanges): void { @@ -76,13 +82,15 @@ export class fPdfViewerComponent implements OnDestroy, OnChanges, AfterViewInit } public zoomIn() { - if (this.zoomValue < 2.5) { + if (this.zoomValue < this.ZOOM_MAX) { this.zoomValue += 0.1; + localStorage.setItem('pdfViewerZoom', this.zoomValue.toString()); } } public zoomOut() { - if (this.zoomValue > 0.5) { + if (this.zoomValue > this.ZOOM_MIN) { this.zoomValue -= 0.1; + localStorage.setItem('pdfViewerZoom', this.zoomValue.toString()); } }