diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2019-12-11 20:20:42 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-12-13 09:13:43 +0100 |
commit | bee29df8a9ba3090be3daa8ff806dd9a26d7a5cf (patch) | |
tree | 9e9f6d509ed24f799f82667109498b9561474a4d /client/src/app/videos/+video-watch/video-watch-playlist.component.ts | |
parent | d816f3a063febac1cad09ab3a32e5f0d29353627 (diff) | |
download | PeerTube-bee29df8a9ba3090be3daa8ff806dd9a26d7a5cf.tar.gz PeerTube-bee29df8a9ba3090be3daa8ff806dd9a26d7a5cf.tar.zst PeerTube-bee29df8a9ba3090be3daa8ff806dd9a26d7a5cf.zip |
autoplay next video support for playlists
Diffstat (limited to 'client/src/app/videos/+video-watch/video-watch-playlist.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/video-watch-playlist.component.ts | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/client/src/app/videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/videos/+video-watch/video-watch-playlist.component.ts index 524055ce2..ed2aeda6e 100644 --- a/client/src/app/videos/+video-watch/video-watch-playlist.component.ts +++ b/client/src/app/videos/+video-watch/video-watch-playlist.component.ts | |||
@@ -3,9 +3,12 @@ import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' | |||
3 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | 3 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
4 | import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' | 4 | import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' |
5 | import { Router } from '@angular/router' | 5 | import { Router } from '@angular/router' |
6 | import { AuthService } from '@app/core' | 6 | import { User, UserService } from '@app/shared' |
7 | import { AuthService, Notifier } from '@app/core' | ||
7 | import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' | 8 | import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' |
8 | import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-element.model' | 9 | import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-element.model' |
10 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | ||
11 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | 12 | ||
10 | @Component({ | 13 | @Component({ |
11 | selector: 'my-video-watch-playlist', | 14 | selector: 'my-video-watch-playlist', |
@@ -13,6 +16,8 @@ import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist- | |||
13 | styleUrls: [ './video-watch-playlist.component.scss' ] | 16 | styleUrls: [ './video-watch-playlist.component.scss' ] |
14 | }) | 17 | }) |
15 | export class VideoWatchPlaylistComponent { | 18 | export class VideoWatchPlaylistComponent { |
19 | static LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST = 'auto_play_video_playlist' | ||
20 | |||
16 | @Input() video: VideoDetails | 21 | @Input() video: VideoDetails |
17 | @Input() playlist: VideoPlaylist | 22 | @Input() playlist: VideoPlaylist |
18 | 23 | ||
@@ -23,14 +28,24 @@ export class VideoWatchPlaylistComponent { | |||
23 | totalItems: null | 28 | totalItems: null |
24 | } | 29 | } |
25 | 30 | ||
31 | autoPlayNextVideoPlaylist: boolean | ||
32 | autoPlayNextVideoPlaylistSwitchText = '' | ||
26 | noPlaylistVideos = false | 33 | noPlaylistVideos = false |
27 | currentPlaylistPosition = 1 | 34 | currentPlaylistPosition = 1 |
28 | 35 | ||
29 | constructor ( | 36 | constructor ( |
37 | private userService: UserService, | ||
30 | private auth: AuthService, | 38 | private auth: AuthService, |
39 | private notifier: Notifier, | ||
40 | private i18n: I18n, | ||
31 | private videoPlaylist: VideoPlaylistService, | 41 | private videoPlaylist: VideoPlaylistService, |
32 | private router: Router | 42 | private router: Router |
33 | ) {} | 43 | ) { |
44 | this.autoPlayNextVideoPlaylist = this.auth.isLoggedIn() | ||
45 | ? this.auth.getUser().autoPlayNextVideoPlaylist | ||
46 | : peertubeLocalStorage.getItem(VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) !== 'false' | ||
47 | this.setAutoPlayNextVideoPlaylistSwitchText() | ||
48 | } | ||
34 | 49 | ||
35 | onPlaylistVideosNearOfBottom () { | 50 | onPlaylistVideosNearOfBottom () { |
36 | // Last page | 51 | // Last page |
@@ -121,4 +136,33 @@ export class VideoWatchPlaylistComponent { | |||
121 | this.router.navigate([],{ queryParams: { videoId: next.video.uuid, start, stop } }) | 136 | this.router.navigate([],{ queryParams: { videoId: next.video.uuid, start, stop } }) |
122 | } | 137 | } |
123 | } | 138 | } |
139 | |||
140 | switchAutoPlayNextVideoPlaylist () { | ||
141 | this.autoPlayNextVideoPlaylist = !this.autoPlayNextVideoPlaylist | ||
142 | this.setAutoPlayNextVideoPlaylistSwitchText() | ||
143 | |||
144 | peertubeLocalStorage.setItem( | ||
145 | VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST, | ||
146 | this.autoPlayNextVideoPlaylist.toString() | ||
147 | ) | ||
148 | |||
149 | if (this.auth.isLoggedIn()) { | ||
150 | const details = { | ||
151 | autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist | ||
152 | } | ||
153 | |||
154 | this.userService.updateMyProfile(details).subscribe( | ||
155 | () => { | ||
156 | this.auth.refreshUserInformation() | ||
157 | }, | ||
158 | err => this.notifier.error(err.message) | ||
159 | ) | ||
160 | } | ||
161 | } | ||
162 | |||
163 | private setAutoPlayNextVideoPlaylistSwitchText () { | ||
164 | this.autoPlayNextVideoPlaylistSwitchText = this.i18n('{{verb}} autoplay for playlists', { | ||
165 | verb: this.autoPlayNextVideoPlaylist ? this.i18n('Disable') : this.i18n('Enable') | ||
166 | }) | ||
167 | } | ||
124 | } | 168 | } |