]>
Commit | Line | Data |
---|---|---|
22a16e36 | 1 | import { Component, OnInit } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
22a16e36 | 3 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
22a16e36 | 4 | import { UserSubscriptionService } from '@app/shared/user-subscription' |
aa55a4da | 5 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
22a16e36 C |
6 | |
7 | @Component({ | |
8 | selector: 'my-account-subscriptions', | |
9 | templateUrl: './my-account-subscriptions.component.html', | |
10 | styleUrls: [ './my-account-subscriptions.component.scss' ] | |
11 | }) | |
12 | export class MyAccountSubscriptionsComponent implements OnInit { | |
13 | videoChannels: VideoChannel[] = [] | |
14 | ||
aa55a4da C |
15 | pagination: ComponentPagination = { |
16 | currentPage: 1, | |
17 | itemsPerPage: 10, | |
18 | totalItems: null | |
19 | } | |
20 | ||
22a16e36 C |
21 | constructor ( |
22 | private userSubscriptionService: UserSubscriptionService, | |
830b4faf | 23 | private notifier: Notifier |
22a16e36 C |
24 | ) {} |
25 | ||
26 | ngOnInit () { | |
aa55a4da C |
27 | this.loadSubscriptions() |
28 | } | |
29 | ||
30 | loadSubscriptions () { | |
31 | this.userSubscriptionService.listSubscriptions(this.pagination) | |
32 | .subscribe( | |
33 | res => { | |
34 | this.videoChannels = this.videoChannels.concat(res.data) | |
35 | this.pagination.totalItems = res.total | |
36 | }, | |
37 | ||
f8b2c1b4 | 38 | error => this.notifier.error(error.message) |
aa55a4da C |
39 | ) |
40 | } | |
41 | ||
42 | onNearOfBottom () { | |
43 | // Last page | |
44 | if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return | |
22a16e36 | 45 | |
aa55a4da C |
46 | this.pagination.currentPage += 1 |
47 | this.loadSubscriptions() | |
22a16e36 C |
48 | } |
49 | ||
50 | } |