]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/recommendations/recommended-videos.store.ts
Add video recomandation by tags (#1001)
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / recommendations / recommended-videos.store.ts
CommitLineData
7f5f4152
BJ
1import { Inject, Injectable } from '@angular/core'
2import { Observable, ReplaySubject } from 'rxjs'
3import { Video } from '@app/shared/video/video.model'
b0c36821 4import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
7f5f4152
BJ
5import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service'
6import { RecommendationService, UUID } from '@app/videos/recommendations/recommendations.service'
7import { map, switchMap, take } from 'rxjs/operators'
8
9/**
10 * This store is intended to provide data for the RecommendedVideosComponent.
11 */
12@Injectable()
13export class RecommendedVideosStore {
14 public readonly recommendations$: Observable<Video[]>
15 public readonly hasRecommendations$: Observable<boolean>
b0c36821 16 private readonly requestsForLoad$$ = new ReplaySubject<RecommendationInfo>(1)
7f5f4152
BJ
17
18 constructor (
19 @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService
20 ) {
21 this.recommendations$ = this.requestsForLoad$$.pipe(
b0c36821 22 switchMap(requestedRecommendation => recommendations.getRecommendations(requestedRecommendation)
7f5f4152
BJ
23 .pipe(take(1))
24 ))
25 this.hasRecommendations$ = this.recommendations$.pipe(
26 map(otherVideos => otherVideos.length > 0)
27 )
28 }
29
b0c36821
J
30 requestNewRecommendations (recommend: RecommendationInfo) {
31 this.requestsForLoad$$.next(recommend)
7f5f4152
BJ
32 }
33}