Don't get recommended videos twice

pull/1093/head
Chocobozzz 2018-09-18 11:59:05 +02:00
parent 098eb37797
commit e972e046db
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 12 additions and 8 deletions

View 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 { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router' import { ActivatedRoute, Router } from '@angular/router'
import { RedirectService } from '@app/core/routing/redirect.service' import { RedirectService } from '@app/core/routing/redirect.service'

View File

@ -25,8 +25,8 @@ export class RecentVideosRecommendationService implements RecommendationService
getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> {
return this.fetchPage(1, recommendation) return this.fetchPage(1, recommendation)
.pipe( .pipe(
map(vids => { map(videos => {
const otherVideos = vids.filter(v => v.uuid !== recommendation.uuid) const otherVideos = videos.filter(v => v.uuid !== recommendation.uuid)
return otherVideos.slice(0, this.pageSize) return otherVideos.slice(0, this.pageSize)
}) })
) )

View File

@ -3,8 +3,8 @@ import { Observable, ReplaySubject } from 'rxjs'
import { Video } from '@app/shared/video/video.model' import { Video } from '@app/shared/video/video.model'
import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service' import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service'
import { RecommendationService, UUID } from '@app/videos/recommendations/recommendations.service' import { RecommendationService } from '@app/videos/recommendations/recommendations.service'
import { map, switchMap, take } from 'rxjs/operators' import { map, shareReplay, switchMap, take } from 'rxjs/operators'
/** /**
* This store is intended to provide data for the RecommendedVideosComponent. * This store is intended to provide data for the RecommendedVideosComponent.
@ -19,9 +19,13 @@ export class RecommendedVideosStore {
@Inject(RecentVideosRecommendationService) private recommendations: RecommendationService @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService
) { ) {
this.recommendations$ = this.requestsForLoad$$.pipe( this.recommendations$ = this.requestsForLoad$$.pipe(
switchMap(requestedRecommendation => recommendations.getRecommendations(requestedRecommendation) switchMap(requestedRecommendation => {
return recommendations.getRecommendations(requestedRecommendation)
.pipe(take(1)) .pipe(take(1))
)) }),
shareReplay()
)
this.hasRecommendations$ = this.recommendations$.pipe( this.hasRecommendations$ = this.recommendations$.pipe(
map(otherVideos => otherVideos.length > 0) map(otherVideos => otherVideos.length > 0)
) )