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