1 import { Component, Input, OnInit } from '@angular/core'
2 import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
3 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
4 import { NotificationsService } from 'angular2-notifications'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
8 selector: 'my-subscribe-button',
9 templateUrl: './subscribe-button.component.html',
10 styleUrls: [ './subscribe-button.component.scss' ]
12 export class SubscribeButtonComponent implements OnInit {
13 @Input() videoChannel: VideoChannel
14 @Input() displayFollowers = false
15 @Input() size: 'small' | 'normal' = 'normal'
20 private notificationsService: NotificationsService,
21 private userSubscriptionService: UserSubscriptionService,
26 return this.videoChannel.name + '@' + this.videoChannel.host
30 this.userSubscriptionService.isSubscriptionExists(this.uri)
32 res => this.subscribed = res[this.uri],
34 err => this.notificationsService.error(this.i18n('Error'), err.message)
39 this.userSubscriptionService.addSubscription(this.uri)
42 this.subscribed = true
44 this.notificationsService.success(
45 this.i18n('Subscribed'),
46 this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
50 err => this.notificationsService.error(this.i18n('Error'), err.message)
55 this.userSubscriptionService.deleteSubscription(this.uri)
58 this.subscribed = false
60 this.notificationsService.success(
61 this.i18n('Unsubscribed'),
62 this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
66 err => this.notificationsService.error(this.i18n('Error'), err.message)