mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
search pending and is searchable
This commit is contained in:
parent
b724448081
commit
d917651d9f
@ -2,6 +2,7 @@ import { CipherView } from '../models/view/cipherView';
|
||||
|
||||
export abstract class SearchService {
|
||||
clearIndex: () => void;
|
||||
isSearchable: (query: string) => boolean;
|
||||
indexCiphers: () => Promise<void>;
|
||||
searchCiphers: (query: string, filter?: (cipher: CipherView) => boolean) => Promise<CipherView[]>;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ export class CiphersComponent {
|
||||
|
||||
protected allCiphers: CipherView[] = [];
|
||||
protected filter: (cipher: CipherView) => boolean = null;
|
||||
protected searchPending = false;
|
||||
|
||||
private searchTimeout: any = null;
|
||||
|
||||
@ -40,15 +41,22 @@ export class CiphersComponent {
|
||||
|
||||
async applyFilter(filter: (cipher: CipherView) => boolean = null) {
|
||||
this.filter = filter;
|
||||
await this.search(0);
|
||||
await this.search(null);
|
||||
}
|
||||
|
||||
search(timeout: number = 0) {
|
||||
async search(timeout: number = null) {
|
||||
this.searchPending = false;
|
||||
if (this.searchTimeout != null) {
|
||||
clearTimeout(this.searchTimeout);
|
||||
}
|
||||
if (timeout == null) {
|
||||
this.ciphers = await this.searchService.searchCiphers(this.searchText, this.filter);
|
||||
return;
|
||||
}
|
||||
this.searchPending = true;
|
||||
this.searchTimeout = setTimeout(async () => {
|
||||
this.ciphers = await this.searchService.searchCiphers(this.searchText, this.filter);
|
||||
this.searchPending = false;
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,12 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
this.index = null;
|
||||
}
|
||||
|
||||
isSearchable(query: string): boolean {
|
||||
const notSearchable = query == null || (this.index == null && query.length < 2) ||
|
||||
(this.index != null && query.length < 2 && query.indexOf('>') !== 0);
|
||||
return !notSearchable;
|
||||
}
|
||||
|
||||
async indexCiphers(): Promise<void> {
|
||||
if (this.indexing) {
|
||||
return;
|
||||
@ -91,7 +97,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
ciphers = ciphers.filter(filter);
|
||||
}
|
||||
|
||||
if (query == null || (this.index == null && query.length < 2)) {
|
||||
if (!this.isSearchable(query)) {
|
||||
return ciphers;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user