From 1fd61899eaea245a5844e33e21f04b2562f16e5e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 May 2021 11:06:19 +0200 Subject: Add ability to filter my videos by live --- client/src/app/core/rest/rest-table.ts | 72 ++-------------------------------- 1 file changed, 3 insertions(+), 69 deletions(-) (limited to 'client/src/app/core/rest/rest-table.ts') diff --git a/client/src/app/core/rest/rest-table.ts b/client/src/app/core/rest/rest-table.ts index 32c1db446..9baab8a39 100644 --- a/client/src/app/core/rest/rest-table.ts +++ b/client/src/app/core/rest/rest-table.ts @@ -1,14 +1,14 @@ import * as debug from 'debug' import { LazyLoadEvent, SortMeta } from 'primeng/api' import { Subject } from 'rxjs' -import { debounceTime, distinctUntilChanged } from 'rxjs/operators' -import { ActivatedRoute, Params, Router } from '@angular/router' +import { ActivatedRoute, Router } from '@angular/router' import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' +import { RouteFilter } from '../routing' import { RestPagination } from './rest-pagination' const logger = debug('peertube:tables:RestTable') -export abstract class RestTable { +export abstract class RestTable extends RouteFilter { abstract totalRecords: number abstract sort: SortMeta @@ -19,8 +19,6 @@ export abstract class RestTable { rowsPerPage = this.rowsPerPageOptions[0] expandedRows = {} - baseRoute: string - protected searchStream: Subject protected route: ActivatedRoute @@ -66,55 +64,6 @@ export abstract class RestTable { peertubeLocalStorage.setItem(this.getSortLocalStorageKey(), JSON.stringify(this.sort)) } - initSearch () { - this.searchStream = new Subject() - - this.searchStream - .pipe( - debounceTime(400), - distinctUntilChanged() - ) - .subscribe(search => { - this.search = search - - logger('On search %s.', this.search) - - this.loadData() - }) - } - - onSearch (event: Event) { - const target = event.target as HTMLInputElement - this.searchStream.next(target.value) - - this.setQueryParams((event.target as HTMLInputElement).value) - } - - setQueryParams (search: string) { - if (!this.baseRoute) return - - const queryParams: Params = {} - - if (search) Object.assign(queryParams, { search }) - this.router.navigate([ this.baseRoute ], { queryParams }) - } - - resetTableFilter () { - this.setTableFilter('') - this.setQueryParams('') - this.resetSearch() - } - - listenToSearchChange () { - this.route.queryParams - .subscribe(params => { - this.search = params.search || '' - - // Primeng table will run an event to load data - this.setTableFilter(this.search) - }) - } - onPage (event: { first: number, rows: number }) { logger('On page %o.', event) @@ -131,21 +80,6 @@ export abstract class RestTable { this.expandedRows = {} } - setTableFilter (filter: string, triggerEvent = true) { - // FIXME: cannot use ViewChild, so create a component for the filter input - const filterInput = document.getElementById('table-filter') as HTMLInputElement - if (!filterInput) return - - filterInput.value = filter - - if (triggerEvent) filterInput.dispatchEvent(new Event('keyup')) - } - - resetSearch () { - this.searchStream.next('') - this.setTableFilter('') - } - protected abstract loadData (): void private getSortLocalStorageKey () { -- cgit v1.2.3