Fix OnInit for subscribe button
Fixing regression introduced in a004ff1726
that initialized component for accounts with no channels before changing
the input a second time.
This commit is contained in:
parent
2ba5ac3354
commit
f8b65c22a9
2 changed files with 24 additions and 21 deletions
|
@ -1,31 +1,31 @@
|
||||||
<div class="btn-group-subscribe btn-group"
|
<div class="btn-group-subscribe btn-group"
|
||||||
[ngClass]="{'subscribe-button': !isAllChannelsSubscribed(), 'unsubscribe-button': isAllChannelsSubscribed(), 'big': isBigButton() }">
|
[ngClass]="{'subscribe-button': !isAllChannelsSubscribed, 'unsubscribe-button': isAllChannelsSubscribed, 'big': isBigButton }">
|
||||||
|
|
||||||
<ng-template #userLoggedOut>
|
<ng-template #userLoggedOut>
|
||||||
<span [ngClass]="{ 'extra-text': isAtLeastOneChannelSubscribed() }">
|
<span [ngClass]="{ 'extra-text': isAtLeastOneChannelSubscribed }">
|
||||||
<ng-container *ngIf="account; then multiple; else single"></ng-container>
|
<ng-container *ngIf="account; then multiple; else single"></ng-container>
|
||||||
<ng-template i18n #single>Subscribe</ng-template>
|
<ng-template i18n #single>Subscribe</ng-template>
|
||||||
<ng-template #multiple>
|
<ng-template #multiple>
|
||||||
<span i18n>Subscribe to all channels</span>
|
<span i18n>Subscribe to all channels</span>
|
||||||
<span *ngIf="isAtLeastOneChannelSubscribed()">{{ subscribeStatus(true).length }}/{{ subscribed.size }}
|
<span *ngIf="isAtLeastOneChannelSubscribed">{{ subscribeStatus(true).length }}/{{ subscribed.size }}
|
||||||
<ng-container i18n>channels subscribed</ng-container>
|
<ng-container i18n>channels subscribed</ng-container>
|
||||||
</span>
|
</span>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</span>
|
</span>
|
||||||
<span *ngIf="!isBigButton() && displayFollowers && videoChannels.length > 1 && videoChannel.followersCount !== 0" class="followers-count">
|
<span *ngIf="!isBigButton && displayFollowers && videoChannels.length > 1 && videoChannel.followersCount !== 0" class="followers-count">
|
||||||
{{ videoChannels[0].followersCount | myNumberFormatter }}
|
{{ videoChannels[0].followersCount | myNumberFormatter }}
|
||||||
</span>
|
</span>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<ng-template #userLoggedIn>
|
<ng-template #userLoggedIn>
|
||||||
<button *ngIf="!isAllChannelsSubscribed()" type="button"
|
<button *ngIf="!isAllChannelsSubscribed" type="button"
|
||||||
class="btn btn-sm" role="button"
|
class="btn btn-sm" role="button"
|
||||||
(click)="subscribe()">
|
(click)="subscribe()">
|
||||||
<ng-template [ngTemplateOutlet]="userLoggedOut"></ng-template>
|
<ng-template [ngTemplateOutlet]="userLoggedOut"></ng-template>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
*ngIf="isAllChannelsSubscribed()" type="button"
|
*ngIf="isAllChannelsSubscribed" type="button"
|
||||||
class="btn btn-sm" role="button"
|
class="btn btn-sm" role="button"
|
||||||
(click)="unsubscribe()">
|
(click)="unsubscribe()">
|
||||||
<ng-container i18n>{account + "", select, undefined {Unsubscribe} other {Unsubscribe from all channels}}</ng-container>
|
<ng-container i18n>{account + "", select, undefined {Unsubscribe} other {Unsubscribe from all channels}}</ng-container>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Component, Input, OnInit } from '@angular/core'
|
import { Component, Input, OnInit, OnChanges } from '@angular/core'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
import { AuthService, Notifier } from '@app/core'
|
import { AuthService, Notifier } from '@app/core'
|
||||||
import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
|
import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
|
||||||
|
@ -8,14 +8,13 @@ import { VideoService } from '@app/shared/video/video.service'
|
||||||
import { FeedFormat } from '../../../../../shared/models/feeds'
|
import { FeedFormat } from '../../../../../shared/models/feeds'
|
||||||
import { Account } from '@app/shared/account/account.model'
|
import { Account } from '@app/shared/account/account.model'
|
||||||
import { concat, forkJoin, merge } from 'rxjs'
|
import { concat, forkJoin, merge } from 'rxjs'
|
||||||
import { toArray } from 'rxjs/operators'
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-subscribe-button',
|
selector: 'my-subscribe-button',
|
||||||
templateUrl: './subscribe-button.component.html',
|
templateUrl: './subscribe-button.component.html',
|
||||||
styleUrls: [ './subscribe-button.component.scss' ]
|
styleUrls: [ './subscribe-button.component.scss' ]
|
||||||
})
|
})
|
||||||
export class SubscribeButtonComponent implements OnInit {
|
export class SubscribeButtonComponent implements OnInit, OnChanges {
|
||||||
/**
|
/**
|
||||||
* SubscribeButtonComponent can be used with a single VideoChannel passed as [VideoChannel],
|
* SubscribeButtonComponent can be used with a single VideoChannel passed as [VideoChannel],
|
||||||
* or with an account and a full list of that account's videoChannels. The latter is intended
|
* 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 {
|
||||||
return this.videoChannels[0]
|
return this.videoChannels[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isAllChannelsSubscribed () {
|
||||||
|
return this.subscribeStatus(true).length === this.videoChannels.length
|
||||||
|
}
|
||||||
|
|
||||||
|
get isAtLeastOneChannelSubscribed () {
|
||||||
|
return this.subscribeStatus(true).length > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
get isBigButton () {
|
||||||
|
return this.isUserLoggedIn() && this.videoChannels.length > 1 && this.isAtLeastOneChannelSubscribed
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
this.loadSubscribedStatus()
|
this.loadSubscribedStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnChanges () {
|
||||||
|
this.ngOnInit()
|
||||||
|
}
|
||||||
|
|
||||||
subscribe () {
|
subscribe () {
|
||||||
if (this.isUserLoggedIn()) {
|
if (this.isUserLoggedIn()) {
|
||||||
return this.localSubscribe()
|
return this.localSubscribe()
|
||||||
|
@ -146,18 +161,6 @@ export class SubscribeButtonComponent implements OnInit {
|
||||||
return this.authService.isLoggedIn()
|
return this.authService.isLoggedIn()
|
||||||
}
|
}
|
||||||
|
|
||||||
isAllChannelsSubscribed () {
|
|
||||||
return !Array.from(this.subscribed.values()).includes(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
isAtLeastOneChannelSubscribed () {
|
|
||||||
return this.subscribeStatus(true).length > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
isBigButton () {
|
|
||||||
return this.isUserLoggedIn() && this.videoChannels.length > 1 && this.isAtLeastOneChannelSubscribed()
|
|
||||||
}
|
|
||||||
|
|
||||||
gotoLogin () {
|
gotoLogin () {
|
||||||
this.router.navigate([ '/login' ])
|
this.router.navigate([ '/login' ])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue