]>
Commit | Line | Data |
---|---|---|
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 { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | |
5 | import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' | |
6 | import { User } from '@app/shared' | |
7 | ||
8 | @Component({ | |
9 | selector: 'my-recommended-videos', | |
10 | templateUrl: './recommended-videos.component.html' | |
11 | }) | |
12 | export class RecommendedVideosComponent implements OnChanges { | |
13 | @Input() inputRecommendation: RecommendationInfo | |
14 | @Input() user: User | |
15 | @Output() gotRecommendations = new EventEmitter<Video[]>() | |
16 | ||
17 | readonly hasVideos$: Observable<boolean> | |
18 | readonly videos$: Observable<Video[]> | |
19 | ||
20 | constructor ( | |
21 | private store: RecommendedVideosStore | |
22 | ) { | |
23 | this.videos$ = this.store.recommendations$ | |
24 | this.hasVideos$ = this.store.hasRecommendations$ | |
25 | this.videos$.subscribe(videos => this.gotRecommendations.emit(videos)) | |
26 | } | |
27 | ||
28 | public ngOnChanges (): void { | |
29 | if (this.inputRecommendation) { | |
30 | this.store.requestNewRecommendations(this.inputRecommendation) | |
31 | } | |
32 | } | |
33 | ||
34 | onVideoRemoved () { | |
35 | this.store.requestNewRecommendations(this.inputRecommendation) | |
36 | } | |
37 | } |