]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Don't get recommended videos twice
authorChocobozzz <me@florianbigard.com>
Tue, 18 Sep 2018 09:59:05 +0000 (11:59 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 19 Sep 2018 07:54:36 +0000 (09:54 +0200)
client/src/app/videos/+video-watch/video-watch.component.ts
client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
client/src/app/videos/recommendations/recommended-videos.store.ts

index 834428fa45ce5d91c6186418361c4bc09b8bb876..7a61e355a6a72d400ca2a50276c9345e7bfc70f2 100644 (file)
@@ -1,4 +1,4 @@
-import { catchError, subscribeOn } from 'rxjs/operators'
+import { catchError } from 'rxjs/operators'
 import { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
 import { RedirectService } from '@app/core/routing/redirect.service'
index 4723f7fd038ac028eca38305143a103c847124ed..0ee34b9cb28a5d254f6c37e68be582bcee2c557c 100644 (file)
@@ -25,8 +25,8 @@ export class RecentVideosRecommendationService implements RecommendationService
   getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> {
     return this.fetchPage(1, recommendation)
       .pipe(
-        map(vids => {
-          const otherVideos = vids.filter(v => v.uuid !== recommendation.uuid)
+        map(videos => {
+          const otherVideos = videos.filter(v => v.uuid !== recommendation.uuid)
           return otherVideos.slice(0, this.pageSize)
         })
       )
index eb5c9867f18c1ad2be2914ab5286302329b80baa..858ec3a2789e37a1ddeea131a3488bff8aca2525 100644 (file)
@@ -3,8 +3,8 @@ import { Observable, ReplaySubject } from 'rxjs'
 import { Video } from '@app/shared/video/video.model'
 import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
 import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service'
-import { RecommendationService, UUID } from '@app/videos/recommendations/recommendations.service'
-import { map, switchMap, take } from 'rxjs/operators'
+import { RecommendationService } from '@app/videos/recommendations/recommendations.service'
+import { map, shareReplay, switchMap, take } from 'rxjs/operators'
 
 /**
  * This store is intended to provide data for the RecommendedVideosComponent.
@@ -19,9 +19,13 @@ export class RecommendedVideosStore {
     @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService
   ) {
     this.recommendations$ = this.requestsForLoad$$.pipe(
-      switchMap(requestedRecommendation => recommendations.getRecommendations(requestedRecommendation)
-        .pipe(take(1))
-      ))
+      switchMap(requestedRecommendation => {
+        return recommendations.getRecommendations(requestedRecommendation)
+                              .pipe(take(1))
+      }),
+      shareReplay()
+    )
+
     this.hasRecommendations$ = this.recommendations$.pipe(
       map(otherVideos => otherVideos.length > 0)
     )