aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/user-subscription/subscribe-button.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-01-14 10:58:38 +0100
committerRigel Kent <sendmemail@rigelk.eu>2020-01-14 10:58:42 +0100
commitf8b65c22a9cbf60a1d359c6aa2744baede1ee05f (patch)
treedaa9c74e88e99c8eb3f52827e076f75e30d1ab21 /client/src/app/shared/user-subscription/subscribe-button.component.ts
parent2ba5ac33548b809285025be307960e49e7b3947c (diff)
downloadPeerTube-f8b65c22a9cbf60a1d359c6aa2744baede1ee05f.tar.gz
PeerTube-f8b65c22a9cbf60a1d359c6aa2744baede1ee05f.tar.zst
PeerTube-f8b65c22a9cbf60a1d359c6aa2744baede1ee05f.zip
Fix OnInit for subscribe button
Fixing regression introduced in a004ff172638083d69ed1028d18c9b6222d24da6 that initialized component for accounts with no channels before changing the input a second time.
Diffstat (limited to 'client/src/app/shared/user-subscription/subscribe-button.component.ts')
-rw-r--r--client/src/app/shared/user-subscription/subscribe-button.component.ts33
1 files changed, 18 insertions, 15 deletions
diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.ts b/client/src/app/shared/user-subscription/subscribe-button.component.ts
index 81a0df512..947f34c85 100644
--- a/client/src/app/shared/user-subscription/subscribe-button.component.ts
+++ b/client/src/app/shared/user-subscription/subscribe-button.component.ts
@@ -1,4 +1,4 @@
1import { Component, Input, OnInit } from '@angular/core' 1import { Component, Input, OnInit, OnChanges } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3import { AuthService, Notifier } from '@app/core' 3import { AuthService, Notifier } from '@app/core'
4import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service' 4import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
@@ -8,14 +8,13 @@ import { VideoService } from '@app/shared/video/video.service'
8import { FeedFormat } from '../../../../../shared/models/feeds' 8import { FeedFormat } from '../../../../../shared/models/feeds'
9import { Account } from '@app/shared/account/account.model' 9import { Account } from '@app/shared/account/account.model'
10import { concat, forkJoin, merge } from 'rxjs' 10import { concat, forkJoin, merge } from 'rxjs'
11import { toArray } from 'rxjs/operators'
12 11
13@Component({ 12@Component({
14 selector: 'my-subscribe-button', 13 selector: 'my-subscribe-button',
15 templateUrl: './subscribe-button.component.html', 14 templateUrl: './subscribe-button.component.html',
16 styleUrls: [ './subscribe-button.component.scss' ] 15 styleUrls: [ './subscribe-button.component.scss' ]
17}) 16})
18export class SubscribeButtonComponent implements OnInit { 17export class SubscribeButtonComponent implements OnInit, OnChanges {
19 /** 18 /**
20 * SubscribeButtonComponent can be used with a single VideoChannel passed as [VideoChannel], 19 * SubscribeButtonComponent can be used with a single VideoChannel passed as [VideoChannel],
21 * or with an account and a full list of that account's videoChannels. The latter is intended 20 * or with an account and a full list of that account's videoChannels. The latter is intended
@@ -70,10 +69,26 @@ export class SubscribeButtonComponent implements OnInit {
70 return this.videoChannels[0] 69 return this.videoChannels[0]
71 } 70 }
72 71
72 get isAllChannelsSubscribed () {
73 return this.subscribeStatus(true).length === this.videoChannels.length
74 }
75
76 get isAtLeastOneChannelSubscribed () {
77 return this.subscribeStatus(true).length > 0
78 }
79
80 get isBigButton () {
81 return this.isUserLoggedIn() && this.videoChannels.length > 1 && this.isAtLeastOneChannelSubscribed
82 }
83
73 ngOnInit () { 84 ngOnInit () {
74 this.loadSubscribedStatus() 85 this.loadSubscribedStatus()
75 } 86 }
76 87
88 ngOnChanges () {
89 this.ngOnInit()
90 }
91
77 subscribe () { 92 subscribe () {
78 if (this.isUserLoggedIn()) { 93 if (this.isUserLoggedIn()) {
79 return this.localSubscribe() 94 return this.localSubscribe()
@@ -146,18 +161,6 @@ export class SubscribeButtonComponent implements OnInit {
146 return this.authService.isLoggedIn() 161 return this.authService.isLoggedIn()
147 } 162 }
148 163
149 isAllChannelsSubscribed () {
150 return !Array.from(this.subscribed.values()).includes(false)
151 }
152
153 isAtLeastOneChannelSubscribed () {
154 return this.subscribeStatus(true).length > 0
155 }
156
157 isBigButton () {
158 return this.isUserLoggedIn() && this.videoChannels.length > 1 && this.isAtLeastOneChannelSubscribed()
159 }
160
161 gotoLogin () { 164 gotoLogin () {
162 this.router.navigate([ '/login' ]) 165 this.router.navigate([ '/login' ])
163 } 166 }