1 import { Inject, Injectable } from '@angular/core'
2 import { Observable, ReplaySubject } from 'rxjs'
3 import { Video } from '@app/shared/video/video.model'
4 import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service'
5 import { RecommendationService, UUID } from '@app/videos/recommendations/recommendations.service'
6 import { map, switchMap, take } from 'rxjs/operators'
9 * This store is intended to provide data for the RecommendedVideosComponent.
12 export class RecommendedVideosStore {
13 public readonly recommendations$: Observable<Video[]>
14 public readonly hasRecommendations$: Observable<boolean>
15 private readonly requestsForLoad$$ = new ReplaySubject<UUID>(1)
18 @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService
20 this.recommendations$ = this.requestsForLoad$$.pipe(
21 switchMap(requestedUUID => recommendations.getRecommendations(requestedUUID)
24 this.hasRecommendations$ = this.recommendations$.pipe(
25 map(otherVideos => otherVideos.length > 0)
29 requestNewRecommendations (videoUUID: string) {
30 this.requestsForLoad$$.next(videoUUID)