1
0
Fork 0

Prevent displaying multiple times channels

This commit is contained in:
Chocobozzz 2024-01-11 10:08:10 +01:00
parent b68d2b0698
commit b9e11ea213
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 21 additions and 17 deletions

View file

@ -2,7 +2,7 @@
<span class="text-nowrap me-2"> <span class="text-nowrap me-2">
<my-global-icon iconName="channel" aria-hidden="true"></my-global-icon> <my-global-icon iconName="channel" aria-hidden="true"></my-global-icon>
<ng-container i18n>My channels</ng-container> <ng-container i18n>My channels</ng-container>
<span *ngIf="totalItems" class="pt-badge badge-secondary">{{ totalItems }}</span> <span *ngIf="this.pagination.totalItems" class="pt-badge badge-secondary">{{ this.pagination.totalItems }}</span>
</span> </span>
<div> <div>
@ -24,7 +24,7 @@
</a> </a>
</div> </div>
<div class="no-results" i18n *ngIf="totalItems === 0">No channel found.</div> <div class="no-results" i18n *ngIf="this.pagination.totalItems === 0">No channel found.</div>
<div class="video-channels" myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onChannelDataSubject.asObservable()"> <div class="video-channels" myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onChannelDataSubject.asObservable()">
<div *ngFor="let videoChannel of videoChannels; let i = index" class="video-channel"> <div *ngFor="let videoChannel of videoChannels; let i = index" class="video-channel">

View file

@ -1,6 +1,6 @@
import { ChartData, ChartOptions, TooltipItem, TooltipModel } from 'chart.js' import { ChartData, ChartOptions, TooltipItem, TooltipModel } from 'chart.js'
import { max, maxBy, min, minBy } from 'lodash-es' 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 { Component } from '@angular/core'
import { AuthService, ComponentPagination, ConfirmService, hasMoreItems, Notifier, ScreenService } from '@app/core' import { AuthService, ComponentPagination, ConfirmService, hasMoreItems, Notifier, ScreenService } from '@app/core'
import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
@ -11,8 +11,6 @@ import { formatICU } from '@app/helpers'
styleUrls: [ './my-video-channels.component.scss' ] styleUrls: [ './my-video-channels.component.scss' ]
}) })
export class MyVideoChannelsComponent { export class MyVideoChannelsComponent {
totalItems: number
videoChannels: VideoChannel[] = [] videoChannels: VideoChannel[] = []
videoChannelsChartData: ChartData[] videoChannelsChartData: ChartData[]
@ -29,6 +27,8 @@ export class MyVideoChannelsComponent {
totalItems: null totalItems: null
} }
private pagesDone = new Set<number>()
constructor ( constructor (
private authService: AuthService, private authService: AuthService,
private notifier: Notifier, private notifier: Notifier,
@ -47,8 +47,7 @@ export class MyVideoChannelsComponent {
this.pagination.currentPage = 1 this.pagination.currentPage = 1
this.videoChannels = [] this.videoChannels = []
this.authService.userInformationLoaded this.loadMoreVideoChannels()
.subscribe(() => this.loadMoreVideoChannels())
} }
async deleteVideoChannel (videoChannel: VideoChannel) { async deleteVideoChannel (videoChannel: VideoChannel) {
@ -89,19 +88,24 @@ export class MyVideoChannelsComponent {
} }
private loadMoreVideoChannels () { private loadMoreVideoChannels () {
const user = this.authService.getUser() if (this.pagesDone.has(this.pagination.currentPage)) return
const options = { this.pagesDone.add(this.pagination.currentPage)
account: user.account,
return this.authService.userInformationLoaded
.pipe(
first(),
map(() => ({
account: this.authService.getUser().account,
withStats: true, withStats: true,
search: this.search, search: this.search,
componentPagination: this.pagination, componentPagination: this.pagination,
sort: '-updatedAt' sort: '-updatedAt'
} })),
switchMap(options => this.videoChannelService.listAccountVideoChannels(options))
return this.videoChannelService.listAccountVideoChannels(options) )
.subscribe(res => { .subscribe(res => {
this.videoChannels = this.videoChannels.concat(res.data) this.videoChannels = this.videoChannels.concat(res.data)
this.totalItems = res.total this.pagination.totalItems = res.total
// chart data // chart data
this.videoChannelsChartData = this.videoChannels.map(v => ({ this.videoChannelsChartData = this.videoChannels.map(v => ({