From 24b9417cec5cc785a57b2fe169a1ae88b88801a4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Oct 2018 15:51:38 +0200 Subject: Add users search filter --- client/src/app/shared/rest/rest-table.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'client/src/app/shared/rest') diff --git a/client/src/app/shared/rest/rest-table.ts b/client/src/app/shared/rest/rest-table.ts index fe1a91d2d..26748f245 100644 --- a/client/src/app/shared/rest/rest-table.ts +++ b/client/src/app/shared/rest/rest-table.ts @@ -1,8 +1,9 @@ import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent' import { SortMeta } from 'primeng/components/common/sortmeta' - import { RestPagination } from './rest-pagination' +import { Subject } from 'rxjs' +import { debounceTime, distinctUntilChanged } from 'rxjs/operators' export abstract class RestTable { @@ -11,10 +12,17 @@ export abstract class RestTable { abstract sort: SortMeta abstract pagination: RestPagination + protected search: string + private searchStream: Subject private sortLocalStorageKey = 'rest-table-sort-' + this.constructor.name protected abstract loadData (): void + initialize () { + this.loadSort() + this.initSearch() + } + loadSort () { const result = peertubeLocalStorage.getItem(this.sortLocalStorageKey) @@ -46,4 +54,21 @@ export abstract class RestTable { peertubeLocalStorage.setItem(this.sortLocalStorageKey, JSON.stringify(this.sort)) } + initSearch () { + this.searchStream = new Subject() + + this.searchStream + .pipe( + debounceTime(400), + distinctUntilChanged() + ) + .subscribe(search => { + this.search = search + this.loadData() + }) + } + + onSearch (search: string) { + this.searchStream.next(search) + } } -- cgit v1.2.3