From a004ff172638083d69ed1028d18c9b6222d24da6 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Fri, 10 Jan 2020 16:22:55 +0100 Subject: Add naive aggregation from channels to account display of subscribers --- client/src/app/+accounts/accounts.component.html | 4 +++- client/src/app/+accounts/accounts.component.ts | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'client/src/app/+accounts') diff --git a/client/src/app/+accounts/accounts.component.html b/client/src/app/+accounts/accounts.component.html index be40b63ca..57498e98c 100644 --- a/client/src/app/+accounts/accounts.component.html +++ b/client/src/app/+accounts/accounts.component.html @@ -28,7 +28,9 @@ > -
{account.followersCount, plural, =1 {1 subscriber} other {{{ account.followersCount }} subscribers}}
+
+ {{ subscribersDisplayFor(naiveAggregatedSubscribers) }} +
diff --git a/client/src/app/+accounts/accounts.component.ts b/client/src/app/+accounts/accounts.component.ts index 8bde7ad07..da4a0b28e 100644 --- a/client/src/app/+accounts/accounts.component.ts +++ b/client/src/app/+accounts/accounts.component.ts @@ -18,7 +18,7 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model' export class AccountsComponent implements OnInit, OnDestroy { account: Account user: User - videoChannels: VideoChannel[] + videoChannels: VideoChannel[] = [] private routeSub: Subscription @@ -58,6 +58,13 @@ export class AccountsComponent implements OnInit, OnDestroy { if (this.routeSub) this.routeSub.unsubscribe() } + get naiveAggregatedSubscribers () { + return this.videoChannels.reduce( + (acc, val) => acc + val.followersCount, + this.account.followersCount // accumulator starts with the base number of subscribers the account has + ) + } + onUserChanged () { this.getUserIfNeeded(this.account) } @@ -70,6 +77,10 @@ export class AccountsComponent implements OnInit, OnDestroy { this.notifier.success(this.i18n('Username copied')) } + subscribersDisplayFor (count: number) { + return this.i18n(`{count, plural, =1 {1 subscriber} other {${count} subscribers}}`, { count }) + } + private getUserIfNeeded (account: Account) { if (!account.userId) return if (!this.authService.isLoggedIn()) return -- cgit v1.2.3