]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-watch/recommendations/recommended-videos.store.ts
Move to sass @use
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / recommendations / recommended-videos.store.ts
CommitLineData
7f5f4152 1import { Observable, ReplaySubject } from 'rxjs'
e972e046 2import { map, shareReplay, switchMap, take } from 'rxjs/operators'
67ed6552
C
3import { Inject, Injectable } from '@angular/core'
4import { Video } from '@app/shared/shared-main'
5import { RecentVideosRecommendationService } from './recent-videos-recommendation.service'
6import { RecommendationInfo } from './recommendation-info.model'
7import { RecommendationService } from './recommendations.service'
7f5f4152
BJ
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(
e972e046 22 switchMap(requestedRecommendation => {
67ed6552 23 return this.recommendations.getRecommendations(requestedRecommendation)
e972e046
C
24 .pipe(take(1))
25 }),
26 shareReplay()
27 )
28
7f5f4152
BJ
29 this.hasRecommendations$ = this.recommendations$.pipe(
30 map(otherVideos => otherVideos.length > 0)
31 )
32 }
33
b0c36821
J
34 requestNewRecommendations (recommend: RecommendationInfo) {
35 this.requestsForLoad$$.next(recommend)
7f5f4152
BJ
36 }
37}