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