]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-library/my-subscriptions/my-subscriptions.component.ts
Refactor search filters
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-library / my-subscriptions / my-subscriptions.component.ts
CommitLineData
ad453580 1import { Subject } from 'rxjs'
2e46eb97 2import { Component } from '@angular/core'
67ed6552
C
3import { ComponentPagination, Notifier } from '@app/core'
4import { VideoChannel } from '@app/shared/shared-main'
5import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
22a16e36
C
6
7@Component({
17119e4a
C
8 templateUrl: './my-subscriptions.component.html',
9 styleUrls: [ './my-subscriptions.component.scss' ]
22a16e36 10})
2e46eb97 11export class MySubscriptionsComponent {
22a16e36
C
12 videoChannels: VideoChannel[] = []
13
aa55a4da
C
14 pagination: ComponentPagination = {
15 currentPage: 1,
16 itemsPerPage: 10,
17 totalItems: null
18 }
19
ad453580
C
20 onDataSubject = new Subject<any[]>()
21
2e46eb97 22 search: string
4f5d0459 23
22a16e36
C
24 constructor (
25 private userSubscriptionService: UserSubscriptionService,
830b4faf 26 private notifier: Notifier
22a16e36
C
27 ) {}
28
aa55a4da
C
29 onNearOfBottom () {
30 // Last page
31 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
22a16e36 32
aa55a4da
C
33 this.pagination.currentPage += 1
34 this.loadSubscriptions()
22a16e36
C
35 }
36
2e46eb97
C
37 onSearch (search: string) {
38 this.search = search
39 this.loadSubscriptions(false)
40 }
41
4f5d0459 42 private loadSubscriptions (more = true) {
2e46eb97 43 this.userSubscriptionService.listSubscriptions({ pagination: this.pagination, search: this.search })
4f5d0459
RK
44 .subscribe(
45 res => {
46 this.videoChannels = more
47 ? this.videoChannels.concat(res.data)
48 : res.data
49 this.pagination.totalItems = res.total
50
51 this.onDataSubject.next(res.data)
52 },
53
54 error => this.notifier.error(error.message)
55 )
56 }
22a16e36 57}