From 36004aa7b0de5cb69a452090770221b192a78eb8 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 19 Apr 2020 23:41:05 +0200 Subject: [PATCH] Support search param in URL for video abuses --- .../video-abuse-list.component.html | 6 ++--- .../video-abuse-list.component.ts | 23 +++++++++++++++---- .../app/header/search-typeahead.component.ts | 8 +++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html index c15e98942..9e084cb73 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html @@ -1,5 +1,5 @@ {{ createByString(videoAbuse.reporterAccount) }} - + {videoAbuse.countReportsForReporter, plural, =1 {1 report} other {{{ videoAbuse.countReportsForReporter }} reports}} @@ -142,7 +142,7 @@ {{ videoAbuse.video.channel.ownerAccount ? createByString(videoAbuse.video.channel.ownerAccount) : '' }} - + {videoAbuse.countReportsForReportee, plural, =1 {1 report} other {{{ videoAbuse.countReportsForReportee }} reports}} diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts index 0c727ae90..2ece5dcc1 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild } from '@angular/core' +import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core' import { Account } from '@app/shared/account/account.model' import { Notifier } from '@app/core' import { SortMeta } from 'primeng/api' @@ -17,14 +17,14 @@ import { DomSanitizer } from '@angular/platform-browser' import { BlocklistService } from '@app/shared/blocklist' import { VideoService } from '@app/shared/video/video.service' import { ActivatedRoute } from '@angular/router' -import { first } from 'rxjs/operators' +import { filter } from 'rxjs/operators' @Component({ selector: 'my-video-abuse-list', templateUrl: './video-abuse-list.component.html', styleUrls: [ '../moderation.component.scss', './video-abuse-list.component.scss' ] }) -export class VideoAbuseListComponent extends RestTable implements OnInit { +export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit { @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = [] @@ -190,8 +190,16 @@ export class VideoAbuseListComponent extends RestTable implements OnInit { this.initialize() this.route.queryParams - .pipe(first(params => params.search !== undefined && params.search !== null)) - .subscribe(params => this.search = params.search) + .pipe(filter(params => params.search !== undefined && params.search !== null)) + .subscribe(params => { + this.search = params.search + this.setTableFilter(params.search) + this.loadData() + }) + } + + ngAfterViewInit () { + this.setTableFilter(this.search) } getIdentifier () { @@ -210,6 +218,11 @@ export class VideoAbuseListComponent extends RestTable implements OnInit { return Account.CREATE_BY_STRING(account.name, account.host) } + setTableFilter (filter: string) { + const filterInput = document.getElementById('table-filter') as HTMLInputElement + if (filterInput) filterInput.value = filter + } + isVideoAbuseAccepted (videoAbuse: VideoAbuse) { return videoAbuse.state.id === VideoAbuseState.ACCEPTED } diff --git a/client/src/app/header/search-typeahead.component.ts b/client/src/app/header/search-typeahead.component.ts index d0350368d..2bf1072f4 100644 --- a/client/src/app/header/search-typeahead.component.ts +++ b/client/src/app/header/search-typeahead.component.ts @@ -36,7 +36,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy { ngOnInit () { this.route.queryParams - .pipe(first(params => params.search !== undefined && params.search !== null)) + .pipe(first(params => this.isOnSearch() && params.search !== undefined && params.search !== null)) .subscribe(params => this.search = params.search) this.serverService.getConfig() .subscribe(config => this.serverConfig = config) @@ -146,11 +146,15 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy { } } + isOnSearch () { + return window.location.pathname === '/search' + } + doSearch () { this.newSearch = false const queryParams: Params = {} - if (window.location.pathname === '/search' && this.route.snapshot.queryParams) { + if (this.isOnSearch() && this.route.snapshot.queryParams) { Object.assign(queryParams, this.route.snapshot.queryParams) } -- 2.25.1