aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-22 15:40:13 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit93cae47925e4dd68b7d34a41927b2740b4fab1b4 (patch)
treef649ab49fab1886b434e164591990cc99b234466 /client/src/app/search/search.component.ts
parent587568e1cc0e33c023c1ac62dd28fef313285250 (diff)
downloadPeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.gz
PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.zst
PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.zip
Add client hooks
Diffstat (limited to 'client/src/app/search/search.component.ts')
-rw-r--r--client/src/app/search/search.component.ts46
1 files changed, 39 insertions, 7 deletions
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'
10import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 10import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
11import { immutableAssign } from '@app/shared/misc/utils' 11import { immutableAssign } from '@app/shared/misc/utils'
12import { Video } from '@app/shared/video/video.model' 12import { Video } from '@app/shared/video/video.model'
13import { HooksService } from '@app/core/plugins/hooks.service'
13 14
14@Component({ 15@Component({
15 selector: 'my-search', 16 selector: 'my-search',
@@ -41,7 +42,8 @@ export class SearchComponent implements OnInit, OnDestroy {
41 private metaService: MetaService, 42 private metaService: MetaService,
42 private notifier: Notifier, 43 private notifier: Notifier,
43 private searchService: SearchService, 44 private searchService: SearchService,
44 private authService: AuthService 45 private authService: AuthService,
46 private hooks: HooksService
45 ) { } 47 ) { }
46 48
47 get user () { 49 get user () {
@@ -93,18 +95,18 @@ export class SearchComponent implements OnInit, OnDestroy {
93 95
94 search () { 96 search () {
95 forkJoin([ 97 forkJoin([
96 this.searchService.searchVideos(this.currentSearch, this.pagination, this.advancedSearch), 98 this.getVideosObs(),
97 this.searchService.searchVideoChannels(this.currentSearch, immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage })) 99 this.getVideoChannelObs()
98 ]) 100 ])
99 .subscribe( 101 .subscribe(
100 ([ videosResult, videoChannelsResult ]) => { 102 ([ videosResult, videoChannelsResult ]) => {
101 this.results = this.results 103 this.results = this.results
102 .concat(videoChannelsResult.data) 104 .concat(videoChannelsResult.data)
103 .concat(videosResult.videos) 105 .concat(videosResult.data)
104 this.pagination.totalItems = videosResult.totalVideos + videoChannelsResult.total 106 this.pagination.totalItems = videosResult.total + videoChannelsResult.total
105 107
106 // Focus on channels if there are no enough videos 108 // Focus on channels if there are no enough videos
107 if (this.firstSearch === true && videosResult.videos.length < this.pagination.itemsPerPage) { 109 if (this.firstSearch === true && videosResult.data.length < this.pagination.itemsPerPage) {
108 this.resetPagination() 110 this.resetPagination()
109 this.firstSearch = false 111 this.firstSearch = false
110 112
@@ -117,7 +119,6 @@ export class SearchComponent implements OnInit, OnDestroy {
117 119
118 err => this.notifier.error(err.message) 120 err => this.notifier.error(err.message)
119 ) 121 )
120
121 } 122 }
122 123
123 onNearOfBottom () { 124 onNearOfBottom () {
@@ -163,4 +164,35 @@ export class SearchComponent implements OnInit, OnDestroy {
163 queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search }) 164 queryParams: Object.assign({}, this.advancedSearch.toUrlObject(), { search })
164 }) 165 })
165 } 166 }
167
168 private getVideosObs () {
169 const params = {
170 search: this.currentSearch,
171 componentPagination: this.pagination,
172 advancedSearch: this.advancedSearch
173 }
174
175 return this.hooks.wrapObsFun(
176 this.searchService.searchVideos.bind(this.searchService),
177 params,
178 'common',
179 'filter:api.search.videos.list.params',
180 'filter:api.search.videos.list.result'
181 )
182 }
183
184 private getVideoChannelObs () {
185 const params = {
186 search: this.currentSearch,
187 componentPagination: immutableAssign(this.pagination, { itemsPerPage: this.channelsPerPage })
188 }
189
190 return this.hooks.wrapObsFun(
191 this.searchService.searchVideoChannels.bind(this.searchService),
192 params,
193 'common',
194 'filter:api.search.video-channels.list.params',
195 'filter:api.search.video-channels.list.result'
196 )
197 }
166} 198}