]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-subscriptions / my-account-subscriptions.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { UserSubscriptionService } from '@app/shared/user-subscription'
6 import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
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
16 pagination: ComponentPagination = {
17 currentPage: 1,
18 itemsPerPage: 10,
19 totalItems: null
20 }
21
22 constructor (
23 private userSubscriptionService: UserSubscriptionService,
24 private notifier: Notifier,
25 private i18n: I18n
26 ) {}
27
28 ngOnInit () {
29 this.loadSubscriptions()
30 }
31
32 loadSubscriptions () {
33 this.userSubscriptionService.listSubscriptions(this.pagination)
34 .subscribe(
35 res => {
36 this.videoChannels = this.videoChannels.concat(res.data)
37 this.pagination.totalItems = res.total
38 },
39
40 error => this.notifier.error(error.message)
41 )
42 }
43
44 onNearOfBottom () {
45 // Last page
46 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
47
48 this.pagination.currentPage += 1
49 this.loadSubscriptions()
50 }
51
52 }