1 import { Subject } from 'rxjs'
2 import { Component } from '@angular/core'
3 import { ComponentPagination, Notifier } from '@app/core'
4 import { VideoChannel } from '@app/shared/shared-main'
5 import { UserSubscriptionService } from '@app/shared/shared-user-subscription'
8 templateUrl: './my-subscriptions.component.html',
9 styleUrls: [ './my-subscriptions.component.scss' ]
11 export class MySubscriptionsComponent {
12 videoChannels: VideoChannel[] = []
14 pagination: ComponentPagination = {
20 onDataSubject = new Subject<any[]>()
25 private userSubscriptionService: UserSubscriptionService,
26 private notifier: Notifier
31 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
33 this.pagination.currentPage += 1
34 this.loadSubscriptions()
37 onSearch (search: string) {
39 this.loadSubscriptions(false)
42 private loadSubscriptions (more = true) {
43 this.userSubscriptionService.listSubscriptions({ pagination: this.pagination, search: this.search })
46 this.videoChannels = more
47 ? this.videoChannels.concat(res.data)
49 this.pagination.totalItems = res.total
51 this.onDataSubject.next(res.data)
54 error: err => this.notifier.error(err.message)