Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PS-1335] problem with dropped letters keypresses when searching vault from browser extension debounce #3680

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/browser/src/popup/vault/current-tab.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ <h1 class="sr-only">{{ "currentTab" | i18n }}</h1>
placeholder="{{ 'searchVault' | i18n }}"
id="search"
[(ngModel)]="searchText"
(input)="searchVault()"
(input)="search$.next()"
autocomplete="off"
(keydown)="closeOnEsc($event)"
appAutofocus
/>
<i class="bwi bwi-search" aria-hidden="true"></i>
</div>
Expand Down
21 changes: 12 additions & 9 deletions apps/browser/src/popup/vault/current-tab.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { Subject } from "rxjs";
import { debounceTime, takeUntil } from "rxjs/operators";

import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
Expand Down Expand Up @@ -40,6 +42,8 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
loaded = false;
isLoading = false;
showOrganizations = false;
protected search$ = new Subject<void>();
private destroy$ = new Subject<void>();

private totpCode: string;
private totpTimeout: number;
Expand Down Expand Up @@ -105,14 +109,17 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
}, 5000);
}

window.setTimeout(() => {
document.getElementById("search").focus();
}, 100);
this.search$
.pipe(debounceTime(500), takeUntil(this.destroy$))
.subscribe(() => this.searchVault());
}

ngOnDestroy() {
window.clearTimeout(this.loadedTimeout);
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);

this.destroy$.next();
this.destroy$.complete();
}

async refresh() {
Expand Down Expand Up @@ -179,15 +186,11 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
}

searchVault() {
if (this.searchTimeout != null) {
clearTimeout(this.searchTimeout);
}
if (!this.searchService.isSearchable(this.searchText)) {
return;
}
this.searchTimeout = window.setTimeout(async () => {
this.router.navigate(["/tabs/vault"], { queryParams: { searchText: this.searchText } });
}, 200);

this.router.navigate(["/tabs/vault"], { queryParams: { searchText: this.searchText } });
}

closeOnEsc(e: KeyboardEvent) {
Expand Down