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-video-channels.component.html | 7 +--- .../my-video-channels.component.ts | 46 +++++++--------------- 2 files changed, 16 insertions(+), 37 deletions(-) (limited to 'client/src/app/+my-library/+my-video-channels') diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html index 2ed0c93d6..8d5eb04e2 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html +++ b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html @@ -5,12 +5,7 @@
-
- - - Clear filters -
+ diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts index f6ba50a48..9e3bf35b4 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts +++ b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts @@ -1,29 +1,26 @@ import { ChartData } from 'chart.js' import { max, maxBy, min, minBy } from 'lodash-es' -import { Subject } from 'rxjs' -import { debounceTime, mergeMap } from 'rxjs/operators' -import { Component, OnInit } from '@angular/core' -import { AuthService, ConfirmService, Notifier, ScreenService, User } from '@app/core' +import { mergeMap } from 'rxjs/operators' +import { Component } from '@angular/core' +import { AuthService, ConfirmService, Notifier, ScreenService } from '@app/core' import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' @Component({ templateUrl: './my-video-channels.component.html', styleUrls: [ './my-video-channels.component.scss' ] }) -export class MyVideoChannelsComponent implements OnInit { +export class MyVideoChannelsComponent { totalItems: number videoChannels: VideoChannel[] = [] + videoChannelsChartData: ChartData[] videoChannelsMinimumDailyViews = 0 videoChannelsMaximumDailyViews: number - channelsSearch: string - channelsSearchChanged = new Subject() - chartOptions: any - private user: User + search: string constructor ( private authService: AuthService, @@ -31,31 +28,15 @@ export class MyVideoChannelsComponent implements OnInit { private confirmService: ConfirmService, private videoChannelService: VideoChannelService, private screenService: ScreenService - ) {} - - ngOnInit () { - this.user = this.authService.getUser() - - this.loadVideoChannels() - - this.channelsSearchChanged - .pipe(debounceTime(500)) - .subscribe(() => { - this.loadVideoChannels() - }) - } + ) {} get isInSmallView () { return this.screenService.isInSmallView() } - resetSearch () { - this.channelsSearch = '' - this.onChannelsSearchChanged() - } - - onChannelsSearchChanged () { - this.channelsSearchChanged.next() + onSearch (search: string) { + this.search = search + this.loadVideoChannels() } async deleteVideoChannel (videoChannel: VideoChannel) { @@ -85,8 +66,11 @@ channel with the same name (${videoChannel.name})!`, private loadVideoChannels () { this.authService.userInformationLoaded - .pipe(mergeMap(() => this.videoChannelService.listAccountVideoChannels(this.user.account, null, true, this.channelsSearch))) - .subscribe(res => { + .pipe(mergeMap(() => { + const user = this.authService.getUser() + + return this.videoChannelService.listAccountVideoChannels(user.account, null, true, this.search) + })).subscribe(res => { this.videoChannels = res.data this.totalItems = res.total -- cgit v1.2.3