aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/recommendations/recommended-videos.component.ts
blob: 7e0fb88567ad442b14d44d42726ac5cf8943c221 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core'
import { Observable } from 'rxjs'
import { Video } from '@app/shared/video/video.model'
import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store'
import { User } from '@app/shared'

@Component({
  selector: 'my-recommended-videos',
  templateUrl: './recommended-videos.component.html'
})
export class RecommendedVideosComponent implements OnChanges {
  @Input() inputRecommendation: RecommendationInfo
  @Input() user: User
  @Output() gotRecommendations = new EventEmitter<Video[]>()

  readonly hasVideos$: Observable<boolean>
  readonly videos$: Observable<Video[]>

  constructor (
    private store: RecommendedVideosStore
  ) {
    this.videos$ = this.store.recommendations$
    this.hasVideos$ = this.store.hasRecommendations$
    this.videos$.subscribe(videos => this.gotRecommendations.emit(videos))
  }

  public ngOnChanges (): void {
    if (this.inputRecommendation) {
      this.store.requestNewRecommendations(this.inputRecommendation)
    }
  }

  onVideoRemoved () {
    this.store.requestNewRecommendations(this.inputRecommendation)
  }
}