diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-22 15:40:13 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 93cae47925e4dd68b7d34a41927b2740b4fab1b4 (patch) | |
tree | f649ab49fab1886b434e164591990cc99b234466 /client/src/app/shared | |
parent | 587568e1cc0e33c023c1ac62dd28fef313285250 (diff) | |
download | PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.gz PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.tar.zst PeerTube-93cae47925e4dd68b7d34a41927b2740b4fab1b4.zip |
Add client hooks
Diffstat (limited to 'client/src/app/shared')
4 files changed, 21 insertions, 20 deletions
diff --git a/client/src/app/shared/overview/overview.service.ts b/client/src/app/shared/overview/overview.service.ts index 98dba2d97..bd4068925 100644 --- a/client/src/app/shared/overview/overview.service.ts +++ b/client/src/app/shared/overview/overview.service.ts | |||
@@ -45,7 +45,7 @@ export class OverviewService { | |||
45 | of(object.videos) | 45 | of(object.videos) |
46 | .pipe( | 46 | .pipe( |
47 | switchMap(videos => this.videosService.extractVideos({ total: 0, data: videos })), | 47 | switchMap(videos => this.videosService.extractVideos({ total: 0, data: videos })), |
48 | map(result => result.videos), | 48 | map(result => result.data), |
49 | tap(videos => { | 49 | tap(videos => { |
50 | videosOverviewResult[key].push(immutableAssign(object, { videos })) | 50 | videosOverviewResult[key].push(immutableAssign(object, { videos })) |
51 | }) | 51 | }) |
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index cf4b5ef8e..8a247a9af 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts | |||
@@ -13,6 +13,7 @@ import { Notifier, ServerService } from '@app/core' | |||
13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' | 13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' |
14 | import { I18n } from '@ngx-translate/i18n-polyfill' | 14 | import { I18n } from '@ngx-translate/i18n-polyfill' |
15 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' | 15 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' |
16 | import { ResultList } from '@shared/models' | ||
16 | 17 | ||
17 | enum GroupDate { | 18 | enum GroupDate { |
18 | UNKNOWN = 0, | 19 | UNKNOWN = 0, |
@@ -73,7 +74,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
73 | private groupedDateLabels: { [id in GroupDate]: string } | 74 | private groupedDateLabels: { [id in GroupDate]: string } |
74 | private groupedDates: { [id: number]: GroupDate } = {} | 75 | private groupedDates: { [id: number]: GroupDate } = {} |
75 | 76 | ||
76 | abstract getVideosObservable (page: number): Observable<{ videos: Video[], totalVideos: number }> | 77 | abstract getVideosObservable (page: number): Observable<ResultList<Video>> |
77 | 78 | ||
78 | abstract generateSyndicationList (): void | 79 | abstract generateSyndicationList (): void |
79 | 80 | ||
@@ -138,12 +139,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor | |||
138 | } | 139 | } |
139 | 140 | ||
140 | loadMoreVideos () { | 141 | loadMoreVideos () { |
141 | const observable = this.getVideosObservable(this.pagination.currentPage) | 142 | this.getVideosObservable(this.pagination.currentPage).subscribe( |
142 | 143 | ({ data, total }) => { | |
143 | observable.subscribe( | 144 | this.pagination.totalItems = total |
144 | ({ videos, totalVideos }) => { | 145 | this.videos = this.videos.concat(data) |
145 | this.pagination.totalItems = totalVideos | ||
146 | this.videos = this.videos.concat(videos) | ||
147 | 146 | ||
148 | if (this.groupByDate) this.buildGroupedDateLabels() | 147 | if (this.groupByDate) this.buildGroupedDateLabels() |
149 | 148 | ||
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index 871bc9e46..d1af13c93 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts | |||
@@ -41,7 +41,7 @@ export interface VideosProvider { | |||
41 | filter?: VideoFilter, | 41 | filter?: VideoFilter, |
42 | categoryOneOf?: number, | 42 | categoryOneOf?: number, |
43 | languageOneOf?: string[] | 43 | languageOneOf?: string[] |
44 | }): Observable<{ videos: Video[], totalVideos: number }> | 44 | }): Observable<ResultList<Video>> |
45 | } | 45 | } |
46 | 46 | ||
47 | @Injectable() | 47 | @Injectable() |
@@ -65,11 +65,11 @@ export class VideoService implements VideosProvider { | |||
65 | return VideoService.BASE_VIDEO_URL + uuid + '/watching' | 65 | return VideoService.BASE_VIDEO_URL + uuid + '/watching' |
66 | } | 66 | } |
67 | 67 | ||
68 | getVideo (uuid: string): Observable<VideoDetails> { | 68 | getVideo (options: { videoId: string }): Observable<VideoDetails> { |
69 | return this.serverService.localeObservable | 69 | return this.serverService.localeObservable |
70 | .pipe( | 70 | .pipe( |
71 | switchMap(translations => { | 71 | switchMap(translations => { |
72 | return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid) | 72 | return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + options.videoId) |
73 | .pipe(map(videoHash => ({ videoHash, translations }))) | 73 | .pipe(map(videoHash => ({ videoHash, translations }))) |
74 | }), | 74 | }), |
75 | map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)), | 75 | map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)), |
@@ -123,7 +123,7 @@ export class VideoService implements VideosProvider { | |||
123 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 123 | .pipe(catchError(err => this.restExtractor.handleError(err))) |
124 | } | 124 | } |
125 | 125 | ||
126 | getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<{ videos: Video[], totalVideos: number }> { | 126 | getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<ResultList<Video>> { |
127 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 127 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
128 | 128 | ||
129 | let params = new HttpParams() | 129 | let params = new HttpParams() |
@@ -141,7 +141,7 @@ export class VideoService implements VideosProvider { | |||
141 | account: Account, | 141 | account: Account, |
142 | videoPagination: ComponentPagination, | 142 | videoPagination: ComponentPagination, |
143 | sort: VideoSortField | 143 | sort: VideoSortField |
144 | ): Observable<{ videos: Video[], totalVideos: number }> { | 144 | ): Observable<ResultList<Video>> { |
145 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 145 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
146 | 146 | ||
147 | let params = new HttpParams() | 147 | let params = new HttpParams() |
@@ -159,7 +159,7 @@ export class VideoService implements VideosProvider { | |||
159 | videoChannel: VideoChannel, | 159 | videoChannel: VideoChannel, |
160 | videoPagination: ComponentPagination, | 160 | videoPagination: ComponentPagination, |
161 | sort: VideoSortField | 161 | sort: VideoSortField |
162 | ): Observable<{ videos: Video[], totalVideos: number }> { | 162 | ): Observable<ResultList<Video>> { |
163 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 163 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
164 | 164 | ||
165 | let params = new HttpParams() | 165 | let params = new HttpParams() |
@@ -176,7 +176,7 @@ export class VideoService implements VideosProvider { | |||
176 | getPlaylistVideos ( | 176 | getPlaylistVideos ( |
177 | videoPlaylistId: number | string, | 177 | videoPlaylistId: number | string, |
178 | videoPagination: ComponentPagination | 178 | videoPagination: ComponentPagination |
179 | ): Observable<{ videos: Video[], totalVideos: number }> { | 179 | ): Observable<ResultList<Video>> { |
180 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 180 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
181 | 181 | ||
182 | let params = new HttpParams() | 182 | let params = new HttpParams() |
@@ -190,10 +190,11 @@ export class VideoService implements VideosProvider { | |||
190 | ) | 190 | ) |
191 | } | 191 | } |
192 | 192 | ||
193 | getUserSubscriptionVideos ( | 193 | getUserSubscriptionVideos (parameters: { |
194 | videoPagination: ComponentPagination, | 194 | videoPagination: ComponentPagination, |
195 | sort: VideoSortField | 195 | sort: VideoSortField |
196 | ): Observable<{ videos: Video[], totalVideos: number }> { | 196 | }): Observable<ResultList<Video>> { |
197 | const { videoPagination, sort } = parameters | ||
197 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 198 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
198 | 199 | ||
199 | let params = new HttpParams() | 200 | let params = new HttpParams() |
@@ -213,7 +214,7 @@ export class VideoService implements VideosProvider { | |||
213 | filter?: VideoFilter, | 214 | filter?: VideoFilter, |
214 | categoryOneOf?: number, | 215 | categoryOneOf?: number, |
215 | languageOneOf?: string[] | 216 | languageOneOf?: string[] |
216 | }): Observable<{ videos: Video[], totalVideos: number }> { | 217 | }): Observable<ResultList<Video>> { |
217 | const { videoPagination, sort, filter, categoryOneOf, languageOneOf } = parameters | 218 | const { videoPagination, sort, filter, categoryOneOf, languageOneOf } = parameters |
218 | 219 | ||
219 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 220 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
@@ -344,7 +345,7 @@ export class VideoService implements VideosProvider { | |||
344 | videos.push(new Video(videoJson, translations)) | 345 | videos.push(new Video(videoJson, translations)) |
345 | } | 346 | } |
346 | 347 | ||
347 | return { videos, totalVideos } | 348 | return { total: totalVideos, data: videos } |
348 | }) | 349 | }) |
349 | ) | 350 | ) |
350 | } | 351 | } |
diff --git a/client/src/app/shared/video/videos-selection.component.ts b/client/src/app/shared/video/videos-selection.component.ts index d69f7b70e..994e0fa1e 100644 --- a/client/src/app/shared/video/videos-selection.component.ts +++ b/client/src/app/shared/video/videos-selection.component.ts | |||
@@ -21,6 +21,7 @@ import { PeerTubeTemplateDirective } from '@app/shared/angular/peertube-template | |||
21 | import { VideoSortField } from '@app/shared/video/sort-field.type' | 21 | import { VideoSortField } from '@app/shared/video/sort-field.type' |
22 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 22 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
23 | import { I18n } from '@ngx-translate/i18n-polyfill' | 23 | import { I18n } from '@ngx-translate/i18n-polyfill' |
24 | import { ResultList } from '@shared/models' | ||
24 | 25 | ||
25 | export type SelectionType = { [ id: number ]: boolean } | 26 | export type SelectionType = { [ id: number ]: boolean } |
26 | 27 | ||
@@ -33,7 +34,7 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni | |||
33 | @Input() pagination: ComponentPagination | 34 | @Input() pagination: ComponentPagination |
34 | @Input() titlePage: string | 35 | @Input() titlePage: string |
35 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions | 36 | @Input() miniatureDisplayOptions: MiniatureDisplayOptions |
36 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<{ videos: Video[], totalVideos: number }> | 37 | @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<ResultList<Video>> |
37 | @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective> | 38 | @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective> |
38 | 39 | ||
39 | @Output() selectionChange = new EventEmitter<SelectionType>() | 40 | @Output() selectionChange = new EventEmitter<SelectionType>() |