From f0e71330ac356338f67ed51aa2f729c5ce7167c7 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Mon, 18 Nov 2024 11:05:00 -0800
Subject: [PATCH] Enhancement: next / previous shortcuts for document list
(#8309)
---
src-ui/messages.xlf | 18 +++++++++++--
.../document-list.component.spec.ts | 26 +++++++++++++++++++
.../document-list/document-list.component.ts | 24 +++++++++++++++++
3 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf
index e988a39cb..3eee47eb8 100644
--- a/src-ui/messages.xlf
+++ b/src-ui/messages.xlf
@@ -7405,18 +7405,32 @@
264
+
+ Previous page
+
+ src/app/components/document-list/document-list.component.ts
+ 280
+
+
+
+ Next page
+
+ src/app/components/document-list/document-list.component.ts
+ 292
+
+
View "" saved successfully.
src/app/components/document-list/document-list.component.ts
- 300
+ 324
View "" created successfully.
src/app/components/document-list/document-list.component.ts
- 343
+ 367
diff --git a/src-ui/src/app/components/document-list/document-list.component.spec.ts b/src-ui/src/app/components/document-list/document-list.component.spec.ts
index 0a8faa4d3..823fb6e6c 100644
--- a/src-ui/src/app/components/document-list/document-list.component.spec.ts
+++ b/src-ui/src/app/components/document-list/document-list.component.spec.ts
@@ -698,5 +698,31 @@ describe('DocumentListComponent', () => {
fixture.detectChanges()
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' }))
expect(detailSpy).toHaveBeenCalledWith(docs[1].id)
+
+ const lotsOfDocs: Document[] = Array.from({ length: 100 }, (_, i) => ({
+ id: i + 1,
+ title: `Doc${i + 1}`,
+ notes: [],
+ tags$: new Subject(),
+ content: `document content ${i + 1}`,
+ }))
+ jest
+ .spyOn(documentListService, 'documents', 'get')
+ .mockReturnValue(lotsOfDocs)
+ jest
+ .spyOn(documentService, 'listAllFilteredIds')
+ .mockReturnValue(of(lotsOfDocs.map((d) => d.id)))
+ jest.spyOn(documentListService, 'getLastPage').mockReturnValue(4)
+ fixture.detectChanges()
+
+ expect(component.list.currentPage).toEqual(1)
+ document.dispatchEvent(
+ new KeyboardEvent('keydown', { key: 'ArrowRight', ctrlKey: true })
+ )
+ expect(component.list.currentPage).toEqual(2)
+ document.dispatchEvent(
+ new KeyboardEvent('keydown', { key: 'ArrowLeft', ctrlKey: true })
+ )
+ expect(component.list.currentPage).toEqual(1)
})
})
diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts
index 1c559da05..c21c78fc8 100644
--- a/src-ui/src/app/components/document-list/document-list.component.ts
+++ b/src-ui/src/app/components/document-list/document-list.component.ts
@@ -273,6 +273,30 @@ export class DocumentListComponent
}
}
})
+
+ this.hotKeyService
+ .addShortcut({
+ keys: 'control.arrowleft',
+ description: $localize`Previous page`,
+ })
+ .pipe(takeUntil(this.unsubscribeNotifier))
+ .subscribe(() => {
+ if (this.list.currentPage > 1) {
+ this.list.currentPage--
+ }
+ })
+
+ this.hotKeyService
+ .addShortcut({
+ keys: 'control.arrowright',
+ description: $localize`Next page`,
+ })
+ .pipe(takeUntil(this.unsubscribeNotifier))
+ .subscribe(() => {
+ if (this.list.currentPage < this.list.getLastPage()) {
+ this.list.currentPage++
+ }
+ })
}
ngOnDestroy() {