]>
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' |
ad453580 | 6 | import { Subject } from 'rxjs' |
22a16e36 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-account-subscriptions', | |
10 | templateUrl: './my-account-subscriptions.component.html', | |
11 | styleUrls: [ './my-account-subscriptions.component.scss' ] | |
12 | }) | |
13 | export class MyAccountSubscriptionsComponent implements OnInit { | |
14 | videoChannels: VideoChannel[] = [] | |
15 | ||
aa55a4da C |
16 | pagination: ComponentPagination = { |
17 | currentPage: 1, | |
18 | itemsPerPage: 10, | |
19 | totalItems: null | |
20 | } | |
21 | ||
ad453580 C |
22 | onDataSubject = new Subject<any[]>() |
23 | ||
22a16e36 C |
24 | constructor ( |
25 | private userSubscriptionService: UserSubscriptionService, | |
830b4faf | 26 | private notifier: Notifier |
22a16e36 C |
27 | ) {} |
28 | ||
29 | ngOnInit () { | |
aa55a4da C |
30 | this.loadSubscriptions() |
31 | } | |
32 | ||
33 | loadSubscriptions () { | |
34 | this.userSubscriptionService.listSubscriptions(this.pagination) | |
35 | .subscribe( | |
36 | res => { | |
37 | this.videoChannels = this.videoChannels.concat(res.data) | |
38 | this.pagination.totalItems = res.total | |
ad453580 C |
39 | |
40 | this.onDataSubject.next(res.data) | |
aa55a4da C |
41 | }, |
42 | ||
f8b2c1b4 | 43 | error => this.notifier.error(error.message) |
aa55a4da C |
44 | ) |
45 | } | |
46 | ||
47 | onNearOfBottom () { | |
48 | // Last page | |
49 | if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return | |
22a16e36 | 50 | |
aa55a4da C |
51 | this.pagination.currentPage += 1 |
52 | this.loadSubscriptions() | |
22a16e36 C |
53 | } |
54 | ||
55 | } |