aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts
blob: 9517a37059fbc97d9f9f5ba224c529a391ea2ae6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Component, OnInit } from '@angular/core'
import { NotificationsService } from 'angular2-notifications'
import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { UserSubscriptionService } from '@app/shared/user-subscription'
import { ComponentPagination } from '@app/shared/rest/component-pagination.model'

@Component({
  selector: 'my-account-subscriptions',
  templateUrl: './my-account-subscriptions.component.html',
  styleUrls: [ './my-account-subscriptions.component.scss' ]
})
export class MyAccountSubscriptionsComponent implements OnInit {
  videoChannels: VideoChannel[] = []

  pagination: ComponentPagination = {
    currentPage: 1,
    itemsPerPage: 10,
    totalItems: null
  }

  constructor (
    private userSubscriptionService: UserSubscriptionService,
    private notificationsService: NotificationsService,
    private i18n: I18n
  ) {}

  ngOnInit () {
    this.loadSubscriptions()
  }

  loadSubscriptions () {
    this.userSubscriptionService.listSubscriptions(this.pagination)
        .subscribe(
          res => {
            this.videoChannels = this.videoChannels.concat(res.data)
            this.pagination.totalItems = res.total
          },

          error => this.notificationsService.error(this.i18n('Error'), error.message)
        )
  }

  onNearOfBottom () {
    // Last page
    if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return

    this.pagination.currentPage += 1
    this.loadSubscriptions()
  }

}