remove unused imports
[oweals/peertube.git] / client / src / app / shared / user-subscription / subscribe-button.component.ts
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'
6
7 @Component({
8   selector: 'my-subscribe-button',
9   templateUrl: './subscribe-button.component.html',
10   styleUrls: [ './subscribe-button.component.scss' ]
11 })
12 export class SubscribeButtonComponent implements OnInit {
13   @Input() videoChannel: VideoChannel
14   @Input() displayFollowers = false
15   @Input() size: 'small' | 'normal' = 'normal'
16
17   subscribed: boolean
18
19   constructor (
20     private notificationsService: NotificationsService,
21     private userSubscriptionService: UserSubscriptionService,
22     private i18n: I18n
23   ) { }
24
25   get uri () {
26     return this.videoChannel.name + '@' + this.videoChannel.host
27   }
28
29   ngOnInit () {
30     this.userSubscriptionService.isSubscriptionExists(this.uri)
31       .subscribe(
32         res => this.subscribed = res[this.uri],
33
34         err => this.notificationsService.error(this.i18n('Error'), err.message)
35       )
36   }
37
38   subscribe () {
39     this.userSubscriptionService.addSubscription(this.uri)
40       .subscribe(
41         () => {
42           this.subscribed = true
43
44           this.notificationsService.success(
45             this.i18n('Subscribed'),
46             this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
47           )
48         },
49
50           err => this.notificationsService.error(this.i18n('Error'), err.message)
51       )
52   }
53
54   unsubscribe () {
55     this.userSubscriptionService.deleteSubscription(this.uri)
56         .subscribe(
57           () => {
58             this.subscribed = false
59
60             this.notificationsService.success(
61               this.i18n('Unsubscribed'),
62               this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName })
63             )
64           },
65
66           err => this.notificationsService.error(this.i18n('Error'), err.message)
67         )
68   }
69 }