]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-library/my-subscriptions/my-subscriptions.component.ts
fix remote subscribe input alignment
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-subscriptions / my-subscriptions.component.ts
1 import { Subject } from 'rxjs'
2 import { debounceTime } from 'rxjs/operators'
3 import { Component, OnInit } from '@angular/core'
4 import { ComponentPagination, Notifier } from '@app/core'
5 import { VideoChannel } from '@app/shared/shared-main'
6 import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
7
8 @Component({
9 templateUrl: './my-subscriptions.component.html',
10 styleUrls: [ './my-subscriptions.component.scss' ]
11 })
12 export class MySubscriptionsComponent implements OnInit {
13 videoChannels: VideoChannel[] = []
14
15 pagination: ComponentPagination = {
16 currentPage: 1,
17 itemsPerPage: 10,
18 totalItems: null
19 }
20
21 onDataSubject = new Subject<any[]>()
22
23 subscriptionsSearch: string
24 subscriptionsSearchChanged = new Subject<string>()
25
26 constructor (
27 private userSubscriptionService: UserSubscriptionService,
28 private notifier: Notifier
29 ) {}
30
31 ngOnInit () {
32 this.loadSubscriptions()
33
34 this.subscriptionsSearchChanged
35 .pipe(debounceTime(500))
36 .subscribe(() => {
37 this.pagination.currentPage = 1
38 this.loadSubscriptions(false)
39 })
40 }
41
42 resetSearch () {
43 this.subscriptionsSearch = ''
44 this.onSubscriptionsSearchChanged()
45 }
46
47 onSubscriptionsSearchChanged () {
48 this.subscriptionsSearchChanged.next()
49 }
50
51 onNearOfBottom () {
52 // Last page
53 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
54
55 this.pagination.currentPage += 1
56 this.loadSubscriptions()
57 }
58
59 private loadSubscriptions (more = true) {
60 this.userSubscriptionService.listSubscriptions({ pagination: this.pagination, search: this.subscriptionsSearch })
61 .subscribe(
62 res => {
63 this.videoChannels = more
64 ? this.videoChannels.concat(res.data)
65 : res.data
66 this.pagination.totalItems = res.total
67
68 this.onDataSubject.next(res.data)
69 },
70
71 error => this.notifier.error(error.message)
72 )
73 }
74 }