aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search
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
parent587568e1cc0e33c023c1ac62dd28fef313285250 (diff)
downloadPeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.gz
PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.zst
PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.zip
Add client hooks
Diffstat (limited to 'client/src/app/search')
-rw-r--r--client/src/app/search/search.component.ts46
-rw-r--r--client/src/app/search/search.service.ts14
2 files changed, 47 insertions, 13 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}
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts
index cd3bdad35..8f137a321 100644
--- a/client/src/app/search/search.service.ts
+++ b/client/src/app/search/search.service.ts
@@ -23,13 +23,14 @@ export class SearchService {
23 private videoService: VideoService 23 private videoService: VideoService
24 ) {} 24 ) {}
25 25
26 searchVideos ( 26 searchVideos (parameters: {
27 search: string, 27 search: string,
28 componentPagination: ComponentPagination, 28 componentPagination: ComponentPagination,
29 advancedSearch: AdvancedSearch 29 advancedSearch: AdvancedSearch
30 ): Observable<{ videos: Video[], totalVideos: number }> { 30 }): Observable<ResultList<Video>> {
31 const url = SearchService.BASE_SEARCH_URL + 'videos' 31 const { search, componentPagination, advancedSearch } = parameters
32 32
33 const url = SearchService.BASE_SEARCH_URL + 'videos'
33 const pagination = this.restService.componentPaginationToRestPagination(componentPagination) 34 const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
34 35
35 let params = new HttpParams() 36 let params = new HttpParams()
@@ -48,12 +49,13 @@ export class SearchService {
48 ) 49 )
49 } 50 }
50 51
51 searchVideoChannels ( 52 searchVideoChannels (parameters: {
52 search: string, 53 search: string,
53 componentPagination: ComponentPagination 54 componentPagination: ComponentPagination
54 ): Observable<{ data: VideoChannel[], total: number }> { 55 }): Observable<ResultList<VideoChannel>> {
55 const url = SearchService.BASE_SEARCH_URL + 'video-channels' 56 const { search, componentPagination } = parameters
56 57
58 const url = SearchService.BASE_SEARCH_URL + 'video-channels'
57 const pagination = this.restService.componentPaginationToRestPagination(componentPagination) 59 const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
58 60
59 let params = new HttpParams() 61 let params = new HttpParams()