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/shared/overview/overview.service.ts | 2 +- client/src/app/shared/video/abstract-video-list.ts | 13 ++++++------ client/src/app/shared/video/video.service.ts | 23 +++++++++++----------- .../app/shared/video/videos-selection.component.ts | 3 ++- 4 files changed, 21 insertions(+), 20 deletions(-) (limited to 'client/src/app/shared') 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 { of(object.videos) .pipe( switchMap(videos => this.videosService.extractVideos({ total: 0, data: videos })), - map(result => result.videos), + map(result => result.data), tap(videos => { videosOverviewResult[key].push(immutableAssign(object, { videos })) }) 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' import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' import { I18n } from '@ngx-translate/i18n-polyfill' import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' +import { ResultList } from '@shared/models' enum GroupDate { UNKNOWN = 0, @@ -73,7 +74,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor private groupedDateLabels: { [id in GroupDate]: string } private groupedDates: { [id: number]: GroupDate } = {} - abstract getVideosObservable (page: number): Observable<{ videos: Video[], totalVideos: number }> + abstract getVideosObservable (page: number): Observable> abstract generateSyndicationList (): void @@ -138,12 +139,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor } loadMoreVideos () { - const observable = this.getVideosObservable(this.pagination.currentPage) - - observable.subscribe( - ({ videos, totalVideos }) => { - this.pagination.totalItems = totalVideos - this.videos = this.videos.concat(videos) + this.getVideosObservable(this.pagination.currentPage).subscribe( + ({ data, total }) => { + this.pagination.totalItems = total + this.videos = this.videos.concat(data) if (this.groupByDate) this.buildGroupedDateLabels() 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 { filter?: VideoFilter, categoryOneOf?: number, languageOneOf?: string[] - }): Observable<{ videos: Video[], totalVideos: number }> + }): Observable> } @Injectable() @@ -65,11 +65,11 @@ export class VideoService implements VideosProvider { return VideoService.BASE_VIDEO_URL + uuid + '/watching' } - getVideo (uuid: string): Observable { + getVideo (options: { videoId: string }): Observable { return this.serverService.localeObservable .pipe( switchMap(translations => { - return this.authHttp.get(VideoService.BASE_VIDEO_URL + uuid) + return this.authHttp.get(VideoService.BASE_VIDEO_URL + options.videoId) .pipe(map(videoHash => ({ videoHash, translations }))) }), map(({ videoHash, translations }) => new VideoDetails(videoHash, translations)), @@ -123,7 +123,7 @@ export class VideoService implements VideosProvider { .pipe(catchError(err => this.restExtractor.handleError(err))) } - getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<{ videos: Video[], totalVideos: number }> { + getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -141,7 +141,7 @@ export class VideoService implements VideosProvider { account: Account, videoPagination: ComponentPagination, sort: VideoSortField - ): Observable<{ videos: Video[], totalVideos: number }> { + ): Observable> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -159,7 +159,7 @@ export class VideoService implements VideosProvider { videoChannel: VideoChannel, videoPagination: ComponentPagination, sort: VideoSortField - ): Observable<{ videos: Video[], totalVideos: number }> { + ): Observable> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -176,7 +176,7 @@ export class VideoService implements VideosProvider { getPlaylistVideos ( videoPlaylistId: number | string, videoPagination: ComponentPagination - ): Observable<{ videos: Video[], totalVideos: number }> { + ): Observable> { const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -190,10 +190,11 @@ export class VideoService implements VideosProvider { ) } - getUserSubscriptionVideos ( + getUserSubscriptionVideos (parameters: { videoPagination: ComponentPagination, sort: VideoSortField - ): Observable<{ videos: Video[], totalVideos: number }> { + }): Observable> { + const { videoPagination, sort } = parameters const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -213,7 +214,7 @@ export class VideoService implements VideosProvider { filter?: VideoFilter, categoryOneOf?: number, languageOneOf?: string[] - }): Observable<{ videos: Video[], totalVideos: number }> { + }): Observable> { const { videoPagination, sort, filter, categoryOneOf, languageOneOf } = parameters const pagination = this.restService.componentPaginationToRestPagination(videoPagination) @@ -344,7 +345,7 @@ export class VideoService implements VideosProvider { videos.push(new Video(videoJson, translations)) } - return { videos, totalVideos } + return { total: totalVideos, data: videos } }) ) } 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 import { VideoSortField } from '@app/shared/video/sort-field.type' import { ComponentPagination } from '@app/shared/rest/component-pagination.model' import { I18n } from '@ngx-translate/i18n-polyfill' +import { ResultList } from '@shared/models' export type SelectionType = { [ id: number ]: boolean } @@ -33,7 +34,7 @@ export class VideosSelectionComponent extends AbstractVideoList implements OnIni @Input() pagination: ComponentPagination @Input() titlePage: string @Input() miniatureDisplayOptions: MiniatureDisplayOptions - @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable<{ videos: Video[], totalVideos: number }> + @Input() getVideosObservableFunction: (page: number, sort?: VideoSortField) => Observable> @ContentChildren(PeerTubeTemplateDirective) templates: QueryList @Output() selectionChange = new EventEmitter() -- cgit v1.2.3