From b9e11ea213fe993467f9f2e181b2ddf2547dd849 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jan 2024 10:08:10 +0100 Subject: [PATCH] Prevent displaying multiple times channels --- .../my-video-channels.component.html | 4 +-- .../my-video-channels.component.ts | 34 +++++++++++-------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html index 154836854..58a43272e 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html +++ b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.html @@ -2,7 +2,7 @@ My channels - {{ totalItems }} + {{ this.pagination.totalItems }}
@@ -24,7 +24,7 @@
-
No channel found.
+
No channel found.
diff --git a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts index fd63fc22b..56297a31b 100644 --- a/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts +++ b/client/src/app/+my-library/+my-video-channels/my-video-channels.component.ts @@ -1,6 +1,6 @@ import { ChartData, ChartOptions, TooltipItem, TooltipModel } from 'chart.js' import { max, maxBy, min, minBy } from 'lodash-es' -import { Subject } from 'rxjs' +import { Subject, first, map, switchMap } from 'rxjs' import { Component } from '@angular/core' import { AuthService, ComponentPagination, ConfirmService, hasMoreItems, Notifier, ScreenService } from '@app/core' import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' @@ -11,8 +11,6 @@ import { formatICU } from '@app/helpers' styleUrls: [ './my-video-channels.component.scss' ] }) export class MyVideoChannelsComponent { - totalItems: number - videoChannels: VideoChannel[] = [] videoChannelsChartData: ChartData[] @@ -29,6 +27,8 @@ export class MyVideoChannelsComponent { totalItems: null } + private pagesDone = new Set() + constructor ( private authService: AuthService, private notifier: Notifier, @@ -47,8 +47,7 @@ export class MyVideoChannelsComponent { this.pagination.currentPage = 1 this.videoChannels = [] - this.authService.userInformationLoaded - .subscribe(() => this.loadMoreVideoChannels()) + this.loadMoreVideoChannels() } async deleteVideoChannel (videoChannel: VideoChannel) { @@ -89,19 +88,24 @@ export class MyVideoChannelsComponent { } private loadMoreVideoChannels () { - const user = this.authService.getUser() - const options = { - account: user.account, - withStats: true, - search: this.search, - componentPagination: this.pagination, - sort: '-updatedAt' - } + if (this.pagesDone.has(this.pagination.currentPage)) return + this.pagesDone.add(this.pagination.currentPage) - return this.videoChannelService.listAccountVideoChannels(options) + return this.authService.userInformationLoaded + .pipe( + first(), + map(() => ({ + account: this.authService.getUser().account, + withStats: true, + search: this.search, + componentPagination: this.pagination, + sort: '-updatedAt' + })), + switchMap(options => this.videoChannelService.listAccountVideoChannels(options)) + ) .subscribe(res => { this.videoChannels = this.videoChannels.concat(res.data) - this.totalItems = res.total + this.pagination.totalItems = res.total // chart data this.videoChannelsChartData = this.videoChannels.map(v => ({