diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.ts b/frontend/src/app/components/blocks-list/blocks-list.component.ts index 026b0f076..94afb6509 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.ts +++ b/frontend/src/app/components/blocks-list/blocks-list.component.ts @@ -26,7 +26,6 @@ export class BlocksList implements OnInit { auditAvailable = false; isLoading = true; fromBlockHeight = undefined; - lastKeyNavTime = 0; lastBlockHeightFetched = -1; paginationMaxSize: number; page = 1; @@ -77,6 +76,7 @@ export class BlocksList implements OnInit { this.keyNavigationSubscription = this.stateService.keyNavigation$ .pipe( tap((event) => { + this.isLoading = true; const prevKey = this.dir === 'ltr' ? 'ArrowLeft' : 'ArrowRight'; const nextKey = this.dir === 'ltr' ? 'ArrowRight' : 'ArrowLeft'; if (event.key === prevKey && this.page > 1) { @@ -184,10 +184,6 @@ export class BlocksList implements OnInit { this.router.navigate([], { queryParams: { page: page } }); } - keyNavPageChange(page: number): void { - this.pageChange(page); - } - trackByBlock(index: number, block: BlockExtended): number { return block.height; } diff --git a/frontend/src/app/components/liquid-reserves-audit/recent-pegs-list/recent-pegs-list.component.ts b/frontend/src/app/components/liquid-reserves-audit/recent-pegs-list/recent-pegs-list.component.ts index a975e193f..b818dff78 100644 --- a/frontend/src/app/components/liquid-reserves-audit/recent-pegs-list/recent-pegs-list.component.ts +++ b/frontend/src/app/components/liquid-reserves-audit/recent-pegs-list/recent-pegs-list.component.ts @@ -39,10 +39,6 @@ export class RecentPegsListComponent implements OnInit { queryParamSubscription: Subscription; keyNavigationSubscription: Subscription; dir: 'rtl' | 'ltr' = 'ltr'; - lastKeyNavTime = 0; - isArrowKeyPressed = false; - keydownListener: EventListener; - keyupListener: EventListener; private destroy$ = new Subject(); @@ -59,10 +55,6 @@ export class RecentPegsListComponent implements OnInit { if (this.locale.startsWith('ar') || this.locale.startsWith('fa') || this.locale.startsWith('he')) { this.dir = 'rtl'; } - this.keydownListener = this.onKeyDown.bind(this); - this.keyupListener = this.onKeyUp.bind(this); - window.addEventListener('keydown', this.keydownListener); - window.addEventListener('keyup', this.keyupListener); } ngOnInit(): void { @@ -81,23 +73,24 @@ export class RecentPegsListComponent implements OnInit { }), ).subscribe(); - this.keyNavigationSubscription = this.stateService.keyNavigation$.subscribe((event) => { - const prevKey = this.dir === 'ltr' ? 'ArrowLeft' : 'ArrowRight'; - const nextKey = this.dir === 'ltr' ? 'ArrowRight' : 'ArrowLeft'; - if (event.key === prevKey && this.page > 1) { - this.page--; - this.page === 1 ? this.isArrowKeyPressed = false : null; - this.keyNavPageChange(this.page); - this.lastKeyNavTime = Date.now(); - this.cd.markForCheck(); - } - if (event.key === nextKey && this.page < this.pegsCount / this.pageSize) { - this.page++; - this.page >= this.pegsCount / this.pageSize ? this.isArrowKeyPressed = false : null; - this.keyNavPageChange(this.page); - this.lastKeyNavTime = Date.now(); - this.cd.markForCheck(); - } + this.keyNavigationSubscription = this.stateService.keyNavigation$ + .pipe( + tap((event) => { + this.isLoading = true; + const prevKey = this.dir === 'ltr' ? 'ArrowLeft' : 'ArrowRight'; + const nextKey = this.dir === 'ltr' ? 'ArrowRight' : 'ArrowLeft'; + if (event.key === prevKey && this.page > 1) { + this.page--; + this.cd.markForCheck(); + } + if (event.key === nextKey && this.page < this.pegsCount / this.pageSize) { + this.page++; + this.cd.markForCheck(); + } + }), + throttleTime(1000, undefined, { leading: true, trailing: true }), + ).subscribe(() => { + this.pageChange(this.page); }); this.auditStatus$ = this.stateService.blocks$.pipe( @@ -181,39 +174,10 @@ export class RecentPegsListComponent implements OnInit { this.destroy$.complete(); this.queryParamSubscription?.unsubscribe(); this.keyNavigationSubscription?.unsubscribe(); - window.removeEventListener('keydown', this.keydownListener); - window.removeEventListener('keyup', this.keyupListener); - } pageChange(page: number): void { this.router.navigate([], { queryParams: { page: page } }); } - keyNavPageChange(page: number): void { - this.isLoading = true; - if (this.isArrowKeyPressed) { - timer(400).pipe( - take(1), - filter(() => Date.now() - this.lastKeyNavTime >= 400 && this.isArrowKeyPressed === false), - ).subscribe(() => { - this.pageChange(page); - }); - } else { - this.pageChange(page); - } - } - - onKeyDown(event: KeyboardEvent) { - if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') { - this.isArrowKeyPressed = true; - } - } - - onKeyUp(event: KeyboardEvent) { - if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') { - this.isArrowKeyPressed = false; - } - } - }