aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/user-subscription
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-24 10:31:56 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitaa55a4da422330fe2816f1764b64f6607a0ca4aa (patch)
tree39933a835cc13a685696178e374fe3ac8ba9003b /client/src/app/shared/user-subscription
parentf37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (diff)
downloadPeerTube-aa55a4da422330fe2816f1764b64f6607a0ca4aa.tar.gz
PeerTube-aa55a4da422330fe2816f1764b64f6607a0ca4aa.tar.zst
PeerTube-aa55a4da422330fe2816f1764b64f6607a0ca4aa.zip
Infinite scroll to list our subscriptions
Diffstat (limited to 'client/src/app/shared/user-subscription')
-rw-r--r--client/src/app/shared/user-subscription/user-subscription.service.ts18
1 files changed, 11 insertions, 7 deletions
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 @@
1import { bufferTime, catchError, filter, map, share, switchMap, tap } from 'rxjs/operators' 1import { bufferTime, catchError, filter, first, map, share, switchMap } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http' 2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { ResultList } from '../../../../../shared' 4import { ResultList } from '../../../../../shared'
@@ -8,6 +8,7 @@ import { Observable, ReplaySubject, Subject } from 'rxjs'
8import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 8import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' 9import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
10import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos' 10import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
11import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
11 12
12type SubscriptionExistResult = { [ uri: string ]: boolean } 13type SubscriptionExistResult = { [ uri: string ]: boolean }
13 14
@@ -17,7 +18,7 @@ export class UserSubscriptionService {
17 18
18 // Use a replay subject because we "next" a value before subscribing 19 // Use a replay subject because we "next" a value before subscribing
19 private existsSubject: Subject<string> = new ReplaySubject(1) 20 private existsSubject: Subject<string> = new ReplaySubject(1)
20 private existsObservable: Observable<SubscriptionExistResult> 21 private readonly existsObservable: Observable<SubscriptionExistResult>
21 22
22 constructor ( 23 constructor (
23 private authHttp: HttpClient, 24 private authHttp: HttpClient,
@@ -25,7 +26,6 @@ export class UserSubscriptionService {
25 private restService: RestService 26 private restService: RestService
26 ) { 27 ) {
27 this.existsObservable = this.existsSubject.pipe( 28 this.existsObservable = this.existsSubject.pipe(
28 tap(u => console.log(u)),
29 bufferTime(500), 29 bufferTime(500),
30 filter(uris => uris.length !== 0), 30 filter(uris => uris.length !== 0),
31 switchMap(uris => this.areSubscriptionExist(uris)), 31 switchMap(uris => this.areSubscriptionExist(uris)),
@@ -54,10 +54,15 @@ export class UserSubscriptionService {
54 ) 54 )
55 } 55 }
56 56
57 listSubscriptions (): Observable<ResultList<VideoChannel>> { 57 listSubscriptions (componentPagination: ComponentPagination): Observable<ResultList<VideoChannel>> {
58 const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL 58 const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL
59 59
60 return this.authHttp.get<ResultList<VideoChannelServer>>(url) 60 const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
61
62 let params = new HttpParams()
63 params = this.restService.addRestGetParams(params, pagination)
64
65 return this.authHttp.get<ResultList<VideoChannelServer>>(url, { params })
61 .pipe( 66 .pipe(
62 map(res => VideoChannelService.extractVideoChannels(res)), 67 map(res => VideoChannelService.extractVideoChannels(res)),
63 catchError(err => this.restExtractor.handleError(err)) 68 catchError(err => this.restExtractor.handleError(err))
@@ -67,11 +72,10 @@ export class UserSubscriptionService {
67 isSubscriptionExists (nameWithHost: string) { 72 isSubscriptionExists (nameWithHost: string) {
68 this.existsSubject.next(nameWithHost) 73 this.existsSubject.next(nameWithHost)
69 74
70 return this.existsObservable 75 return this.existsObservable.pipe(first())
71 } 76 }
72 77
73 private areSubscriptionExist (uris: string[]): Observable<SubscriptionExistResult> { 78 private areSubscriptionExist (uris: string[]): Observable<SubscriptionExistResult> {
74 console.log(uris)
75 const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/exist' 79 const url = UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/exist'
76 let params = new HttpParams() 80 let params = new HttpParams()
77 81