1 import { Component, Input, OnInit } from '@angular/core'
2 import { AuthService } from '@app/core'
3 import { RestExtractor } from '@app/shared/rest'
4 import { RedirectService } from '@app/core/routing/redirect.service'
5 import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service'
6 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
7 import { NotificationsService } from 'angular2-notifications'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
11 selector: 'my-subscribe-button',
12 templateUrl: './subscribe-button.component.html',
13 styleUrls: [ './subscribe-button.component.scss' ]
15 export class SubscribeButtonComponent implements OnInit {
16 @Input() videoChannel: VideoChannel
17 @Input() displayFollowers = false
18 @Input() size: 'small' | 'normal' = 'normal'
23 private authService: AuthService,
24 private restExtractor: RestExtractor,
25 private redirectService: RedirectService,
26 private notificationsService: NotificationsService,
27 private userSubscriptionService: UserSubscriptionService,
32 return this.videoChannel.name + '@' + this.videoChannel.host
36 this.userSubscriptionService.isSubscriptionExists(this.uri)
38 res => this.subscribed = res[this.uri],
40 err => this.notificationsService.error(this.i18n('Error'), err.message)
45 this.userSubscriptionService.addSubscription(this.uri)
48 this.subscribed = true
50 this.notificationsService.success(
51 this.i18n('Subscribed'),
52 this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
56 err => this.notificationsService.error(this.i18n('Error'), err.message)
61 this.userSubscriptionService.deleteSubscription(this.uri)
64 this.subscribed = false
66 this.notificationsService.success(
67 this.i18n('Unsubscribed'),
68 this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
72 err => this.notificationsService.error(this.i18n('Error'), err.message)