diff options
Diffstat (limited to 'client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts')
-rw-r--r-- | client/src/app/+videos/+video-watch/shared/playlist/video-watch-playlist.component.ts | 39 |
1 files changed, 11 insertions, 28 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 b2863fed6..fbf9a3687 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,16 +1,9 @@ | |||
1 | import { Component, EventEmitter, Input, Output } from '@angular/core' | 1 | import { Component, EventEmitter, Input, Output } from '@angular/core' |
2 | import { Router } from '@angular/router' | 2 | import { Router } from '@angular/router' |
3 | import { | 3 | import { AuthService, ComponentPagination, HooksService, Notifier, SessionStorageService, UserService } from '@app/core' |
4 | AuthService, | ||
5 | ComponentPagination, | ||
6 | HooksService, | ||
7 | LocalStorageService, | ||
8 | Notifier, | ||
9 | SessionStorageService, | ||
10 | UserService | ||
11 | } from '@app/core' | ||
12 | import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' | 4 | import { VideoPlaylist, VideoPlaylistElement, VideoPlaylistService } from '@app/shared/shared-video-playlist' |
13 | import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage' | 5 | import { peertubeSessionStorage } from '@root-helpers/peertube-web-storage' |
6 | import { getBoolOrDefault } from '@root-helpers/local-storage-utils' | ||
14 | import { VideoPlaylistPrivacy } from '@shared/models' | 7 | import { VideoPlaylistPrivacy } from '@shared/models' |
15 | 8 | ||
16 | @Component({ | 9 | @Component({ |
@@ -19,8 +12,7 @@ import { VideoPlaylistPrivacy } from '@shared/models' | |||
19 | styleUrls: [ './video-watch-playlist.component.scss' ] | 12 | styleUrls: [ './video-watch-playlist.component.scss' ] |
20 | }) | 13 | }) |
21 | export class VideoWatchPlaylistComponent { | 14 | export class VideoWatchPlaylistComponent { |
22 | static LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST = 'auto_play_video_playlist' | 15 | static SESSION_STORAGE_LOOP_PLAYLIST = 'loop_playlist' |
23 | static SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST = 'loop_playlist' | ||
24 | 16 | ||
25 | @Input() playlist: VideoPlaylist | 17 | @Input() playlist: VideoPlaylist |
26 | 18 | ||
@@ -47,19 +39,15 @@ export class VideoWatchPlaylistComponent { | |||
47 | private auth: AuthService, | 39 | private auth: AuthService, |
48 | private notifier: Notifier, | 40 | private notifier: Notifier, |
49 | private videoPlaylist: VideoPlaylistService, | 41 | private videoPlaylist: VideoPlaylistService, |
50 | private localStorageService: LocalStorageService, | ||
51 | private sessionStorage: SessionStorageService, | 42 | private sessionStorage: SessionStorageService, |
52 | private router: Router | 43 | private router: Router |
53 | ) { | 44 | ) { |
54 | // defaults to true | 45 | this.userService.getAnonymousOrLoggedUser() |
55 | this.autoPlayNextVideoPlaylist = this.auth.isLoggedIn() | 46 | .subscribe(user => this.autoPlayNextVideoPlaylist = user.autoPlayNextVideoPlaylist) |
56 | ? this.auth.getUser().autoPlayNextVideoPlaylist | ||
57 | : this.localStorageService.getItem(VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) !== 'false' | ||
58 | 47 | ||
59 | this.setAutoPlayNextVideoPlaylistSwitchText() | 48 | this.setAutoPlayNextVideoPlaylistSwitchText() |
60 | 49 | ||
61 | // defaults to false | 50 | this.loopPlaylist = getBoolOrDefault(this.sessionStorage.getItem(VideoWatchPlaylistComponent.SESSION_STORAGE_LOOP_PLAYLIST), false) |
62 | this.loopPlaylist = this.sessionStorage.getItem(VideoWatchPlaylistComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST) === 'true' | ||
63 | this.setLoopPlaylistSwitchText() | 51 | this.setLoopPlaylistSwitchText() |
64 | } | 52 | } |
65 | 53 | ||
@@ -201,16 +189,9 @@ export class VideoWatchPlaylistComponent { | |||
201 | this.autoPlayNextVideoPlaylist = !this.autoPlayNextVideoPlaylist | 189 | this.autoPlayNextVideoPlaylist = !this.autoPlayNextVideoPlaylist |
202 | this.setAutoPlayNextVideoPlaylistSwitchText() | 190 | this.setAutoPlayNextVideoPlaylistSwitchText() |
203 | 191 | ||
204 | peertubeLocalStorage.setItem( | 192 | const details = { autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist } |
205 | VideoWatchPlaylistComponent.LOCAL_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST, | ||
206 | this.autoPlayNextVideoPlaylist.toString() | ||
207 | ) | ||
208 | 193 | ||
209 | if (this.auth.isLoggedIn()) { | 194 | if (this.auth.isLoggedIn()) { |
210 | const details = { | ||
211 | autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist | ||
212 | } | ||
213 | |||
214 | this.userService.updateMyProfile(details) | 195 | this.userService.updateMyProfile(details) |
215 | .subscribe({ | 196 | .subscribe({ |
216 | next: () => { | 197 | next: () => { |
@@ -219,6 +200,8 @@ export class VideoWatchPlaylistComponent { | |||
219 | 200 | ||
220 | error: err => this.notifier.error(err.message) | 201 | error: err => this.notifier.error(err.message) |
221 | }) | 202 | }) |
203 | } else { | ||
204 | this.userService.updateMyAnonymousProfile(details) | ||
222 | } | 205 | } |
223 | } | 206 | } |
224 | 207 | ||
@@ -227,7 +210,7 @@ export class VideoWatchPlaylistComponent { | |||
227 | this.setLoopPlaylistSwitchText() | 210 | this.setLoopPlaylistSwitchText() |
228 | 211 | ||
229 | peertubeSessionStorage.setItem( | 212 | peertubeSessionStorage.setItem( |
230 | VideoWatchPlaylistComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO_PLAYLIST, | 213 | VideoWatchPlaylistComponent.SESSION_STORAGE_LOOP_PLAYLIST, |
231 | this.loopPlaylist.toString() | 214 | this.loopPlaylist.toString() |
232 | ) | 215 | ) |
233 | } | 216 | } |