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'
9 templateUrl: './my-subscriptions.component.html',
10 styleUrls: [ './my-subscriptions.component.scss' ]
12 export class MySubscriptionsComponent implements OnInit {
13 videoChannels: VideoChannel[] = []
15 pagination: ComponentPagination = {
21 onDataSubject = new Subject<any[]>()
23 subscriptionsSearch: string
24 subscriptionsSearchChanged = new Subject<string>()
27 private userSubscriptionService: UserSubscriptionService,
28 private notifier: Notifier
32 this.loadSubscriptions()
34 this.subscriptionsSearchChanged
35 .pipe(debounceTime(500))
37 this.pagination.currentPage = 1
38 this.loadSubscriptions(false)
43 this.subscriptionsSearch = ''
44 this.onSubscriptionsSearchChanged()
47 onSubscriptionsSearchChanged () {
48 this.subscriptionsSearchChanged.next()
53 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
55 this.pagination.currentPage += 1
56 this.loadSubscriptions()
59 private loadSubscriptions (more = true) {
60 this.userSubscriptionService.listSubscriptions({ pagination: this.pagination, search: this.subscriptionsSearch })
63 this.videoChannels = more
64 ? this.videoChannels.concat(res.data)
66 this.pagination.totalItems = res.total
68 this.onDataSubject.next(res.data)
71 error => this.notifier.error(error.message)