Skip to content

Commit d848d09

Browse files
committed
Show new page earlier on page flip, add error feedback for wrong inputs
1 parent d386bbd commit d848d09

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

libs/client-shared/src/lib/components/pdf-viewer/pdf-viewer-navigation/pdf-viewer-navigation.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
<input
2323
#pageInput
2424
class="navigation__page-input"
25+
[class.navigation__page-input--invalid]="showError()"
2526
type="text"
2627
inputmode="numeric"
2728
[value]="currentPage()"
2829
(keydown.enter)="onPageInputSubmit(pageInput)"
2930
(blur)="resetInputValue(pageInput)"
3031
[disabled]="disableInteractions()"
32+
[@shake]="showError()"
33+
(@shake.done)="onShakeDone()"
3134
/>
3235
<span>/ {{ pageCount() }}</span>
3336
} @else {

libs/client-shared/src/lib/components/pdf-viewer/pdf-viewer-navigation/pdf-viewer-navigation.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,10 @@
2929
opacity: 0.5;
3030
cursor: not-allowed;
3131
}
32+
33+
&--invalid {
34+
border-color: var(--sgc-color-error, #d32f2f);
35+
background-color: var(--sgc-color-error-bg, #fdecea);
36+
}
3237
}
3338
}

libs/client-shared/src/lib/components/pdf-viewer/pdf-viewer-navigation/pdf-viewer-navigation.component.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { animate, keyframes, style, transition, trigger } from '@angular/animations';
12
import { CommonModule } from '@angular/common';
2-
import { Component, input, output } from '@angular/core';
3+
import { Component, input, output, signal } from '@angular/core';
34
import { SgcButton, SgcIcon } from '@swissgeol/ui-core-angular';
45

56
export type PdfNavigationAction = 'next' | 'previous' | 'start' | 'end';
@@ -8,13 +9,31 @@ export type PdfNavigationAction = 'next' | 'previous' | 'start' | 'end';
89
imports: [CommonModule, SgcButton, SgcIcon],
910
templateUrl: './pdf-viewer-navigation.component.html',
1011
styleUrl: './pdf-viewer-navigation.component.scss',
12+
animations: [
13+
trigger('shake', [
14+
transition('false => true', [
15+
animate(
16+
'0.4s ease-in-out',
17+
keyframes([
18+
style({ transform: 'translateX(0)', offset: 0 }),
19+
style({ transform: 'translateX(-4px)', offset: 0.2 }),
20+
style({ transform: 'translateX(4px)', offset: 0.4 }),
21+
style({ transform: 'translateX(-3px)', offset: 0.6 }),
22+
style({ transform: 'translateX(3px)', offset: 0.8 }),
23+
style({ transform: 'translateX(0)', offset: 1 }),
24+
]),
25+
),
26+
]),
27+
]),
28+
],
1129
})
1230
export class PdfViewerNavigationComponent {
1331
public readonly currentPage = input<number | undefined>();
1432
public readonly pageCount = input<number | undefined>();
1533
public readonly disableInteractions = input(false);
1634
public readonly navigate = output<PdfNavigationAction>();
1735
public readonly goToPage = output<number>();
36+
protected readonly showError = signal(false);
1837

1938
protected handleNavigate(action: PdfNavigationAction) {
2039
this.navigate.emit(action);
@@ -24,12 +43,18 @@ export class PdfViewerNavigationComponent {
2443
const trimmed = input.value.trim();
2544
const count = this.pageCount();
2645
const page = /^\d+$/.test(trimmed) ? Number.parseInt(trimmed, 10) : Number.NaN;
46+
input.blur();
47+
2748
if (!Number.isNaN(page) && count != null && page >= 1 && page <= count) {
49+
input.value = page.toString();
2850
this.goToPage.emit(page);
2951
} else {
30-
this.resetInputValue(input);
52+
this.showError.set(true);
3153
}
32-
input.blur();
54+
}
55+
56+
protected onShakeDone() {
57+
this.showError.set(false);
3358
}
3459

3560
protected resetInputValue(input: HTMLInputElement) {

libs/client-shared/src/lib/components/pdf-viewer/pdf-viewer.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ export class PdfViewerComponent implements OnDestroy {
288288

289289
private async renderPage(pageNum: number, center?: PdfPageWrapperCenter) {
290290
this.isRendering.set(true);
291+
this.currentPage.set(pageNum);
291292
for (const canvas of this.pdfCanvasElements.values()) {
292293
this.renderer.setStyle(canvas.parentElement, 'display', 'none');
293294
}
@@ -296,7 +297,6 @@ export class PdfViewerComponent implements OnDestroy {
296297
await this.renderPageAndCache(pageNum, center);
297298
}
298299

299-
this.currentPage.set(pageNum);
300300
this.isRendering.set(false);
301301
}
302302

0 commit comments

Comments
 (0)