]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/recommendations/recommended-videos.component.ts
provide specific engine boundaries for nodejs and yarn
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / recommendations / recommended-videos.component.ts
CommitLineData
7f5f4152 1import { Observable } from 'rxjs'
5c20a455
C
2import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
3import { AuthService, Notifier } from '@app/core'
4import { User } from '@app/shared'
5import { SessionStorageService } from '@app/shared/misc/storage.service'
6import { UserService } from '@app/shared/users/user.service'
bee29df8 7import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
b0c36821 8import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
5c20a455
C
9import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
10import { Video } from '@app/shared/video/video.model'
7f5f4152 11import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store'
5def76eb 12import { I18n } from '@ngx-translate/i18n-polyfill'
7f5f4152
BJ
13
14@Component({
15 selector: 'my-recommended-videos',
d816f3a0
RK
16 templateUrl: './recommended-videos.component.html',
17 styleUrls: [ './recommended-videos.component.scss' ]
7f5f4152 18})
5c20a455 19export class RecommendedVideosComponent implements OnInit, OnChanges {
b0c36821 20 @Input() inputRecommendation: RecommendationInfo
bee29df8 21 @Input() playlist: VideoPlaylist
6aa54148 22 @Output() gotRecommendations = new EventEmitter<Video[]>()
7f5f4152 23
8adc5ddb 24 autoPlayNextVideo: boolean
5def76eb 25 autoPlayNextVideoTooltip: string
8adc5ddb 26
c2caa99b
RK
27 displayOptions: MiniatureDisplayOptions = {
28 date: true,
29 views: true,
30 by: true,
31 avatar: true
32 }
33
5c20a455
C
34 userMiniature: User
35
7f5f4152
BJ
36 readonly hasVideos$: Observable<boolean>
37 readonly videos$: Observable<Video[]>
38
39 constructor (
d816f3a0
RK
40 private userService: UserService,
41 private authService: AuthService,
42 private notifier: Notifier,
5def76eb 43 private i18n: I18n,
d3217560
RK
44 private store: RecommendedVideosStore,
45 private sessionStorageService: SessionStorageService
7f5f4152
BJ
46 ) {
47 this.videos$ = this.store.recommendations$
48 this.hasVideos$ = this.store.hasRecommendations$
6aa54148 49 this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
d816f3a0 50
d3217560
RK
51 if (this.authService.isLoggedIn()) {
52 this.autoPlayNextVideo = this.authService.getUser().autoPlayNextVideo
53 } else {
54 this.autoPlayNextVideo = this.sessionStorageService.getItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true' || false
55 this.sessionStorageService.watch([User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO]).subscribe(
56 () => this.autoPlayNextVideo = this.sessionStorageService.getItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true'
57 )
58 }
5def76eb
RK
59
60 this.autoPlayNextVideoTooltip = this.i18n('When active, the next video is automatically played after the current one.')
7f5f4152
BJ
61 }
62
5c20a455
C
63 ngOnInit () {
64 this.userService.getAnonymousOrLoggedUser()
65 .subscribe(user => this.userMiniature = user)
66 }
67
68 ngOnChanges () {
b0c36821
J
69 if (this.inputRecommendation) {
70 this.store.requestNewRecommendations(this.inputRecommendation)
7f5f4152
BJ
71 }
72 }
73
0a57bbff
C
74 onVideoRemoved () {
75 this.store.requestNewRecommendations(this.inputRecommendation)
76 }
d816f3a0
RK
77
78 switchAutoPlayNextVideo () {
d3217560 79 this.sessionStorageService.setItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, this.autoPlayNextVideo.toString())
d816f3a0
RK
80
81 if (this.authService.isLoggedIn()) {
82 const details = {
83 autoPlayNextVideo: this.autoPlayNextVideo
84 }
85
86 this.userService.updateMyProfile(details).subscribe(
87 () => {
88 this.authService.refreshUserInformation()
89 },
90 err => this.notifier.error(err.message)
91 )
92 }
93 }
7f5f4152 94}