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