- this.accountService.accountLoaded
- .pipe(
- tap(account => this.account = account),
- flatMap(account => this.videoChannelService.listAccountVideoChannels(account)),
- map(res => res.data)
- )
- .subscribe(videoChannels => this.videoChannels = videoChannels)
+ this.accountSub = this.accountService.accountLoaded
+ .subscribe(account => {
+ this.account = account
+
+ this.loadMoreChannels()
+ })
+ }
+
+ ngOnDestroy () {
+ if (this.accountSub) this.accountSub.unsubscribe()
+ }
+
+ loadMoreChannels () {
+ this.videoChannelService.listAccountVideoChannels(this.account, this.channelPagination)
+ .pipe(
+ tap(res => this.channelPagination.totalItems = res.total),
+ switchMap(res => from(res.data)),
+ concatMap(videoChannel => {
+ return this.videoService.getVideoChannelVideos(videoChannel, this.videosPagination, this.videosSort)
+ .pipe(map(data => ({ videoChannel, videos: data.videos })))
+ })
+ )
+ .subscribe(({ videoChannel, videos }) => {
+ this.videoChannels.push(videoChannel)
+
+ this.videos[videoChannel.id] = videos
+ })
+ }
+
+ getVideosOf (videoChannel: VideoChannel) {
+ return this.videos[ videoChannel.id ] || []
+ }
+
+ onNearOfBottom () {
+ if (!hasMoreItems(this.channelPagination)) return
+
+ this.channelPagination.currentPage += 1
+
+ this.loadMoreChannels()