]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/recommendations/recommended-videos.component.ts
Update translations
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / recommendations / recommended-videos.component.ts
CommitLineData
6aa54148 1import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core'
7f5f4152
BJ
2import { Observable } from 'rxjs'
3import { Video } from '@app/shared/video/video.model'
bee29df8 4import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
b0c36821 5import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
7f5f4152
BJ
6import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store'
7import { User } from '@app/shared'
d816f3a0
RK
8import { AuthService, Notifier } from '@app/core'
9import { UserService } from '@app/shared/users/user.service'
88a7f93f 10import { peertubeSessionStorage } from '@app/shared/misc/peertube-web-storage'
7f5f4152
BJ
11
12@Component({
13 selector: 'my-recommended-videos',
d816f3a0
RK
14 templateUrl: './recommended-videos.component.html',
15 styleUrls: [ './recommended-videos.component.scss' ]
7f5f4152
BJ
16})
17export class RecommendedVideosComponent implements OnChanges {
88a7f93f 18 static SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO = 'auto_play_next_video'
d816f3a0 19
b0c36821 20 @Input() inputRecommendation: RecommendationInfo
7f5f4152 21 @Input() user: User
bee29df8 22 @Input() playlist: VideoPlaylist
6aa54148 23 @Output() gotRecommendations = new EventEmitter<Video[]>()
7f5f4152 24
8adc5ddb
C
25 autoPlayNextVideo: boolean
26
7f5f4152
BJ
27 readonly hasVideos$: Observable<boolean>
28 readonly videos$: Observable<Video[]>
29
30 constructor (
d816f3a0
RK
31 private userService: UserService,
32 private authService: AuthService,
33 private notifier: Notifier,
7f5f4152
BJ
34 private store: RecommendedVideosStore
35 ) {
36 this.videos$ = this.store.recommendations$
37 this.hasVideos$ = this.store.hasRecommendations$
6aa54148 38 this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
d816f3a0
RK
39
40 this.autoPlayNextVideo = this.authService.isLoggedIn()
41 ? this.authService.getUser().autoPlayNextVideo
88a7f93f 42 : peertubeSessionStorage.getItem(RecommendedVideosComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true' || false
7f5f4152
BJ
43 }
44
45 public ngOnChanges (): void {
b0c36821
J
46 if (this.inputRecommendation) {
47 this.store.requestNewRecommendations(this.inputRecommendation)
7f5f4152
BJ
48 }
49 }
50
0a57bbff
C
51 onVideoRemoved () {
52 this.store.requestNewRecommendations(this.inputRecommendation)
53 }
d816f3a0
RK
54
55 switchAutoPlayNextVideo () {
88a7f93f 56 peertubeSessionStorage.setItem(RecommendedVideosComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, this.autoPlayNextVideo.toString())
d816f3a0
RK
57
58 if (this.authService.isLoggedIn()) {
59 const details = {
60 autoPlayNextVideo: this.autoPlayNextVideo
61 }
62
63 this.userService.updateMyProfile(details).subscribe(
64 () => {
65 this.authService.refreshUserInformation()
66 },
67 err => this.notifier.error(err.message)
68 )
69 }
70 }
7f5f4152 71}