Skip to content

Commit

Permalink
feat: persistent pdf zoom level
Browse files Browse the repository at this point in the history
  • Loading branch information
b0ink committed Sep 28, 2024
1 parent 2965b68 commit 1348da2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/app/common/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 1348da2

Please sign in to comment.