1 import { Observable } from 'rxjs'
2 import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
3 import { AuthService, Notifier, User, UserService } from '@app/core'
4 import { Video } from '@app/shared/shared-main'
5 import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
6 import { VideoPlaylist } from '@app/shared/shared-video-playlist'
7 import { RecommendationInfo } from './recommendation-info.model'
8 import { RecommendedVideosStore } from './recommended-videos.store'
11 selector: 'my-recommended-videos',
12 templateUrl: './recommended-videos.component.html',
13 styleUrls: [ './recommended-videos.component.scss' ]
15 export class RecommendedVideosComponent implements OnInit, OnChanges {
16 @Input() inputRecommendation: RecommendationInfo
17 @Input() playlist: VideoPlaylist
18 @Input() displayAsRow: boolean
20 @Output() gotRecommendations = new EventEmitter<Video[]>()
22 autoPlayNextVideo: boolean
23 autoPlayNextVideoTooltip: string
25 displayOptions: MiniatureDisplayOptions = {
34 readonly hasVideos$: Observable<boolean>
35 readonly videos$: Observable<Video[]>
38 private userService: UserService,
39 private authService: AuthService,
40 private notifier: Notifier,
41 private store: RecommendedVideosStore
43 this.videos$ = this.store.recommendations$
44 this.hasVideos$ = this.store.hasRecommendations$
45 this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
47 this.userService.getAnonymousOrLoggedUser()
48 .subscribe(user => this.autoPlayNextVideo = user.autoPlayNextVideo)
50 this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.`
54 this.userService.getAnonymousOrLoggedUser()
55 .subscribe(user => this.userMiniature = user)
59 if (this.inputRecommendation) {
60 this.store.requestNewRecommendations(this.inputRecommendation)
65 this.store.requestNewRecommendations(this.inputRecommendation)
68 switchAutoPlayNextVideo () {
69 const details = { autoPlayNextVideo: this.autoPlayNextVideo }
71 if (this.authService.isLoggedIn()) {
72 this.userService.updateMyProfile(details)
75 this.authService.refreshUserInformation()
78 error: err => this.notifier.error(err.message)
81 this.userService.updateMyAnonymousProfile(details)