From 2e46eb97154da909b82d5efe1d336a3412594ff0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 May 2021 14:33:34 +0200 Subject: Refactor search filters --- .../+my-library/my-history/my-history.component.ts | 75 ++++++++++++---------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'client/src/app/+my-library/my-history/my-history.component.ts') diff --git a/client/src/app/+my-library/my-history/my-history.component.ts b/client/src/app/+my-library/my-history/my-history.component.ts index 1695bd7ad..ad83db7ab 100644 --- a/client/src/app/+my-library/my-history/my-history.component.ts +++ b/client/src/app/+my-library/my-history/my-history.component.ts @@ -1,36 +1,55 @@ -import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' +import { Subject } from 'rxjs' +import { tap } from 'rxjs/operators' +import { Component, ComponentFactoryResolver, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { AuthService, ComponentPagination, ConfirmService, + DisableForReuseHook, LocalStorageService, Notifier, ScreenService, ServerService, + User, UserService } from '@app/core' import { immutableAssign } from '@app/helpers' -import { UserHistoryService } from '@app/shared/shared-main' -import { AbstractVideoList } from '@app/shared/shared-video-miniature' -import { Subject } from 'rxjs' -import { debounceTime, tap, distinctUntilChanged } from 'rxjs/operators' +import { UserHistoryService, Video } from '@app/shared/shared-main' +import { MiniatureDisplayOptions, VideosSelectionComponent } from '@app/shared/shared-video-miniature' @Component({ templateUrl: './my-history.component.html', styleUrls: [ './my-history.component.scss' ] }) -export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy { +export class MyHistoryComponent implements OnInit, DisableForReuseHook { + @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent + titlePage: string pagination: ComponentPagination = { currentPage: 1, itemsPerPage: 5, totalItems: null } + videosHistoryEnabled: boolean - search: string - protected searchStream: Subject + miniatureDisplayOptions: MiniatureDisplayOptions = { + date: true, + views: true, + by: true, + privacyLabel: false, + privacyText: true, + state: true, + blacklistInfo: true + } + + getVideosObservableFunction = this.getVideosObservable.bind(this) + + user: User + + videos: Video[] = [] + search: string constructor ( protected router: Router, @@ -45,45 +64,31 @@ export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnD private userHistoryService: UserHistoryService, protected cfr: ComponentFactoryResolver ) { - super() - this.titlePage = $localize`My watch history` } ngOnInit () { - super.ngOnInit() + this.user = this.authService.getUser() this.authService.userInformationLoaded - .subscribe(() => { - this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled - }) - - this.searchStream = new Subject() + .subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled) + } - this.searchStream - .pipe( - debounceTime(400), - distinctUntilChanged() - ) - .subscribe(search => { - this.search = search - this.reloadVideos() - }) + disableForReuse () { + this.videosSelection.disableForReuse() } - onSearch (event: Event) { - const target = event.target as HTMLInputElement - this.searchStream.next(target.value) + enabledForReuse () { + this.videosSelection.enabledForReuse() } - resetSearch () { - const searchInput = document.getElementById('history-search') as HTMLInputElement - searchInput.value = '' - this.searchStream.next('') + reloadData () { + this.videosSelection.reloadVideos() } - ngOnDestroy () { - super.ngOnDestroy() + onSearch (search: string) { + this.search = search + this.reloadData() } getVideosObservable (page: number) { @@ -129,7 +134,7 @@ export class MyHistoryComponent extends AbstractVideoList implements OnInit, OnD () => { this.notifier.success($localize`Videos history deleted`) - this.reloadVideos() + this.reloadData() }, err => this.notifier.error(err.message) -- cgit v1.2.3