]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-subscriptions/my-account-subscriptions.component.ts
Use grid to organise settings in admin, my-account
[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 { UserSubscriptionService } from '@app/shared/user-subscription'
5 import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
6 import { Subject } from 'rxjs'
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 onDataSubject = new Subject<any[]>()
23
24 constructor (
25 private userSubscriptionService: UserSubscriptionService,
26 private notifier: Notifier
27 ) {}
28
29 ngOnInit () {
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
39
40 this.onDataSubject.next(res.data)
41 },
42
43 error => this.notifier.error(error.message)
44 )
45 }
46
47 onNearOfBottom () {
48 // Last page
49 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
50
51 this.pagination.currentPage += 1
52 this.loadSubscriptions()
53 }
54
55 }