aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-watch/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+videos/+video-watch/shared')
-rw-r--r--client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts68
1 files changed, 42 insertions, 26 deletions
diff --git a/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts
index 78b3af4a7..b2863fed6 100644
--- a/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts
+++ b/client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts
@@ -1,6 +1,14 @@
1import { Component, EventEmitter, Input, Output } from '@angular/core' 1import { Component, EventEmitter, Input, Output } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3import { AuthService, ComponentPagination, LocalStorageService, Notifier, SessionStorageService, UserService } from '@app/core' 3import {
4 AuthService,
5 ComponentPagination,
6 HooksService,
7 LocalStorageService,
8 Notifier,
9 SessionStorageService,
10 UserService
11} from '@app/core'
4import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' 12import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist'
5import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage' 13import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage'
6import { VideoPlaylistPrivacy } from '@shared/models' 14import { VideoPlaylistPrivacy } from '@shared/models'
@@ -34,6 +42,7 @@ export class VideoWatchPlaylistComponent {
34 currentPlaylistPosition: number 42 currentPlaylistPosition: number
35 43
36 constructor ( 44 constructor (
45 private hooks: HooksService,
37 private userService: UserService, 46 private userService: UserService,
38 private auth: AuthService, 47 private auth: AuthService,
39 private notifier: Notifier, 48 private notifier: Notifier,
@@ -87,31 +96,38 @@ export class VideoWatchPlaylistComponent {
87 } 96 }
88 97
89 loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false, position?: number) { 98 loadPlaylistElements (playlist: VideoPlaylist, redirectToFirst = false, position?: number) {
90 this.videoPlaylist.getPlaylistVideos(playlist.uuid, this.playlistPagination) 99 const obs = this.hooks.wrapObsFun(
91 .subscribe(({ total, data }) => { 100 this.videoPlaylist.getPlaylistVideos.bind(this.videoPlaylist),
92 this.playlistElements = this.playlistElements.concat(data) 101 { videoPlaylistId: playlist.uuid, componentPagination: this.playlistPagination },
93 this.playlistPagination.totalItems = total 102 'video-watch',
94 103 'filter:api.video-watch.video-playlist-elements.get.params',
95 const firstAvailableVideo = this.playlistElements.find(e => !!e.video) 104 'filter:api.video-watch.video-playlist-elements.get.result'
96 if (!firstAvailableVideo) { 105 )
97 this.noPlaylistVideos = true 106
98 return 107 obs.subscribe(({ total, data: playlistElements }) => {
99 } 108 this.playlistElements = this.playlistElements.concat(playlistElements)
100 109 this.playlistPagination.totalItems = total
101 if (position) this.updatePlaylistIndex(position) 110
102 111 const firstAvailableVideo = this.playlistElements.find(e => !!e.video)
103 if (redirectToFirst) { 112 if (!firstAvailableVideo) {
104 const extras = { 113 this.noPlaylistVideos = true
105 queryParams: { 114 return
106 start: firstAvailableVideo.startTimestamp, 115 }
107 stop: firstAvailableVideo.stopTimestamp, 116
108 playlistPosition: firstAvailableVideo.position 117 if (position) this.updatePlaylistIndex(position)
109 }, 118
110 replaceUrl: true 119 if (redirectToFirst) {
111 } 120 const extras = {
112 this.router.navigate([], extras) 121 queryParams: {
113 } 122 start: firstAvailableVideo.startTimestamp,
114 }) 123 stop: firstAvailableVideo.stopTimestamp,
124 playlistPosition: firstAvailableVideo.position
125 },
126 replaceUrl: true
127 }
128 this.router.navigate([], extras)
129 }
130 })
115 } 131 }
116 132
117 updatePlaylistIndex (position: number) { 133 updatePlaylistIndex (position: number) {