From aa55a4da422330fe2816f1764b64f6607a0ca4aa Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Aug 2018 10:31:56 +0200 Subject: Infinite scroll to list our subscriptions --- .../user-subscription/user-subscription.service.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'client/src/app/shared/user-subscription') diff --git a/client/src/app/shared/user-subscription/user-subscription.service.ts b/client/src/app/shared/user-subscription/user-subscription.service.ts index cf622019f..3d05f071e 100644 --- a/client/src/app/shared/user-subscription/user-subscription.service.ts +++ b/client/src/app/shared/user-subscription/user-subscription.service.ts @@ -1,4 +1,4 @@ -import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' +import { bufferTime, catchError, filter, first, map, share, switchMap } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { ResultList } from '../../../../../shared' @@ -8,6 +8,7 @@ import { Observable, ReplaySubject, Subject } from 'rxjs' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' +import { ComponentPagination } from '@app/shared/rest/component-pagination.model' type SubscriptionExistResult = { [ uri: string ]: boolean } @@ -17,7 +18,7 @@ export class UserSubscriptionService { // Use a replay subject because we "next" a value before subscribing private existsSubject: Subject = new ReplaySubject(1) - private existsObservable: Observable + private readonly existsObservable: Observable constructor ( private authHttp: HttpClient, @@ -25,7 +26,6 @@ export class UserSubscriptionService { private restService: RestService ) { this.existsObservable = this.existsSubject.pipe( - tap(u => console.log(u)), bufferTime(500), filter(uris => uris.length !== 0), switchMap(uris => this.areSubscriptionExist(uris)), @@ -54,10 +54,15 @@ export class UserSubscriptionService { ) } - listSubscriptions (): Observable> { + listSubscriptions (componentPagination: ComponentPagination): Observable> { const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL - return this.authHttp.get>(url) + const pagination = this.restService.componentPaginationToRestPagination(componentPagination) + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination) + + return this.authHttp.get>(url, { params }) .pipe( map(res => VideoChannelService.extractVideoChannels(res)), catchError(err => this.restExtractor.handleError(err)) @@ -67,11 +72,10 @@ export class UserSubscriptionService { isSubscriptionExists (nameWithHost: string) { this.existsSubject.next(nameWithHost) - return this.existsObservable + return this.existsObservable.pipe(first()) } private areSubscriptionExist (uris: string[]): Observable { - console.log(uris) const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/exist' let params = new HttpParams() -- cgit v1.2.3