1 import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core'
2 import { Observable } from 'rxjs'
3 import { Video } from '@app/shared/video/video.model'
4 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
5 import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
6 import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store'
7 import { User } from '@app/shared'
8 import { AuthService, Notifier } from '@app/core'
9 import { UserService } from '@app/shared/users/user.service'
10 import { peertubeSessionStorage } from '@app/shared/misc/peertube-web-storage'
13 selector: 'my-recommended-videos',
14 templateUrl: './recommended-videos.component.html',
15 styleUrls: [ './recommended-videos.component.scss' ]
17 export class RecommendedVideosComponent implements OnChanges {
18 static SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO = 'auto_play_next_video'
20 @Input() inputRecommendation: RecommendationInfo
22 @Input() playlist: VideoPlaylist
23 @Output() gotRecommendations = new EventEmitter<Video[]>()
25 readonly hasVideos$: Observable<boolean>
26 readonly videos$: Observable<Video[]>
28 private autoPlayNextVideo: boolean
31 private userService: UserService,
32 private authService: AuthService,
33 private notifier: Notifier,
34 private store: RecommendedVideosStore
36 this.videos$ = this.store.recommendations$
37 this.hasVideos$ = this.store.hasRecommendations$
38 this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
40 this.autoPlayNextVideo = this.authService.isLoggedIn()
41 ? this.authService.getUser().autoPlayNextVideo
42 : peertubeSessionStorage.getItem(RecommendedVideosComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true' || false
45 public ngOnChanges (): void {
46 if (this.inputRecommendation) {
47 this.store.requestNewRecommendations(this.inputRecommendation)
52 this.store.requestNewRecommendations(this.inputRecommendation)
55 switchAutoPlayNextVideo () {
56 peertubeSessionStorage.setItem(RecommendedVideosComponent.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, this.autoPlayNextVideo.toString())
58 if (this.authService.isLoggedIn()) {
60 autoPlayNextVideo: this.autoPlayNextVideo
63 this.userService.updateMyProfile(details).subscribe(
65 this.authService.refreshUserInformation()
67 err => this.notifier.error(err.message)