diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-29 17:18:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-06-29 17:18:39 +0200 |
commit | 911186dae411d78788ccede093c251303187589a (patch) | |
tree | 967a07cd985ae4e2ea5249855726455fe929471d /client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts | |
parent | b0c43e36dbdc2c964f6828a78b146faebfb75b21 (diff) | |
download | PeerTube-911186dae411d78788ccede093c251303187589a.tar.gz PeerTube-911186dae411d78788ccede093c251303187589a.tar.zst PeerTube-911186dae411d78788ccede093c251303187589a.zip |
Reorganize watch components
Diffstat (limited to 'client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts')
-rw-r--r-- | client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts new file mode 100644 index 000000000..89b9c01b6 --- /dev/null +++ b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts | |||
@@ -0,0 +1,95 @@ | |||
1 | import { Observable } from 'rxjs' | ||
2 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' | ||
3 | import { AuthService, Notifier, SessionStorageService, 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 { UserLocalStorageKeys } from '@root-helpers/users' | ||
8 | import { RecommendationInfo } from './recommendation-info.model' | ||
9 | import { RecommendedVideosStore } from './recommended-videos.store' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-recommended-videos', | ||
13 | templateUrl: './recommended-videos.component.html', | ||
14 | styleUrls: [ './recommended-videos.component.scss' ] | ||
15 | }) | ||
16 | export class RecommendedVideosComponent implements OnInit, OnChanges { | ||
17 | @Input() inputRecommendation: RecommendationInfo | ||
18 | @Input() playlist: VideoPlaylist | ||
19 | @Input() displayAsRow: boolean | ||
20 | |||
21 | @Output() gotRecommendations = new EventEmitter<Video[]>() | ||
22 | |||
23 | autoPlayNextVideo: boolean | ||
24 | autoPlayNextVideoTooltip: string | ||
25 | |||
26 | displayOptions: MiniatureDisplayOptions = { | ||
27 | date: true, | ||
28 | views: true, | ||
29 | by: true, | ||
30 | avatar: true | ||
31 | } | ||
32 | |||
33 | userMiniature: User | ||
34 | |||
35 | readonly hasVideos$: Observable<boolean> | ||
36 | readonly videos$: Observable<Video[]> | ||
37 | |||
38 | constructor ( | ||
39 | private userService: UserService, | ||
40 | private authService: AuthService, | ||
41 | private notifier: Notifier, | ||
42 | private store: RecommendedVideosStore, | ||
43 | private sessionStorageService: SessionStorageService | ||
44 | ) { | ||
45 | this.videos$ = this.store.recommendations$ | ||
46 | this.hasVideos$ = this.store.hasRecommendations$ | ||
47 | this.videos$.subscribe(videos => this.gotRecommendations.emit(videos)) | ||
48 | |||
49 | if (this.authService.isLoggedIn()) { | ||
50 | this.autoPlayNextVideo = this.authService.getUser().autoPlayNextVideo | ||
51 | } else { | ||
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 | } | ||
58 | ) | ||
59 | } | ||
60 | |||
61 | this.autoPlayNextVideoTooltip = $localize`When active, the next video is automatically played after the current one.` | ||
62 | } | ||
63 | |||
64 | ngOnInit () { | ||
65 | this.userService.getAnonymousOrLoggedUser() | ||
66 | .subscribe(user => this.userMiniature = user) | ||
67 | } | ||
68 | |||
69 | ngOnChanges () { | ||
70 | if (this.inputRecommendation) { | ||
71 | this.store.requestNewRecommendations(this.inputRecommendation) | ||
72 | } | ||
73 | } | ||
74 | |||
75 | onVideoRemoved () { | ||
76 | this.store.requestNewRecommendations(this.inputRecommendation) | ||
77 | } | ||
78 | |||
79 | switchAutoPlayNextVideo () { | ||
80 | this.sessionStorageService.setItem(UserLocalStorageKeys.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, this.autoPlayNextVideo.toString()) | ||
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 | } | ||
95 | } | ||