From 93cae47925e4dd68b7d34a41927b2740b4fab1b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 22 Jul 2019 15:40:13 +0200 Subject: Add client hooks --- client/src/app/search/search.component.ts | 46 ++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'client/src/app/search/search.component.ts') diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts index a7ddbe1f8..b1d732d68 100644 --- a/client/src/app/search/search.component.ts +++ b/client/src/app/search/search.component.ts @@ -10,6 +10,7 @@ import { AdvancedSearch } from '@app/search/advanced-search.model' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { immutableAssign } from '@app/shared/misc/utils' import { Video } from '@app/shared/video/video.model' +import { HooksService } from '@app/core/plugins/hooks.service' @Component({ selector: 'my-search', @@ -41,7 +42,8 @@ export class SearchComponent implements OnInit, OnDestroy { private metaService: MetaService, private notifier: Notifier, private searchService: SearchService, - private authService: AuthService + private authService: AuthService, + private hooks: HooksService ) { } get user () { @@ -93,18 +95,18 @@ export class SearchComponent implements OnInit, OnDestroy { search () { forkJoin([ - this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch), - this.searchService.searchVideoChannels(this.currentSearch, immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage })) + this.getVideosObs(), + this.getVideoChannelObs() ]) .subscribe( ([ videosResult, videoChannelsResult ]) => { this.results = this.results .concat(videoChannelsResult.data) - .concat(videosResult.videos) - this.pagination.totalItems = videosResult.totalVideos + videoChannelsResult.total + .concat(videosResult.data) + this.pagination.totalItems = videosResult.total + videoChannelsResult.total // Focus on channels if there are no enough videos - if (this.firstSearch === true && videosResult.videos.length < this.pagination.itemsPerPage) { + if (this.firstSearch === true && videosResult.data.length < this.pagination.itemsPerPage) { this.resetPagination() this.firstSearch = false @@ -117,7 +119,6 @@ export class SearchComponent implements OnInit, OnDestroy { err => this.notifier.error(err.message) ) - } onNearOfBottom () { @@ -163,4 +164,35 @@ export class SearchComponent implements OnInit, OnDestroy { queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search }) }) } + + private getVideosObs () { + const params = { + search: this.currentSearch, + componentPagination: this.pagination, + advancedSearch: this.advancedSearch + } + + return this.hooks.wrapObsFun( + this.searchService.searchVideos.bind(this.searchService), + params, + 'common', + 'filter:api.search.videos.list.params', + 'filter:api.search.videos.list.result' + ) + } + + private getVideoChannelObs () { + const params = { + search: this.currentSearch, + componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage }) + } + + return this.hooks.wrapObsFun( + this.searchService.searchVideoChannels.bind(this.searchService), + params, + 'common', + 'filter:api.search.video-channels.list.params', + 'filter:api.search.video-channels.list.result' + ) + } } -- cgit v1.2.3