]>
Commit | Line | Data |
---|---|---|
ad453580 | 1 | import { Subject, Subscription } from 'rxjs' |
67ed6552 C |
2 | import { Component, OnDestroy, OnInit } from '@angular/core' |
3 | import { ComponentPagination, hasMoreItems } from '@app/core' | |
4 | import { VideoChannel, VideoChannelService } from '@app/shared/shared-main' | |
5 | import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' | |
bce47964 C |
6 | |
7 | @Component({ | |
8 | selector: 'my-video-channel-playlists', | |
9 | templateUrl: './video-channel-playlists.component.html', | |
10 | styleUrls: [ './video-channel-playlists.component.scss' ] | |
11 | }) | |
12 | export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy { | |
13 | videoPlaylists: VideoPlaylist[] = [] | |
14 | ||
15 | pagination: ComponentPagination = { | |
16 | currentPage: 1, | |
17 | itemsPerPage: 20, | |
18 | totalItems: null | |
19 | } | |
20 | ||
ad453580 C |
21 | onDataSubject = new Subject<any[]>() |
22 | ||
bce47964 C |
23 | private videoChannelSub: Subscription |
24 | private videoChannel: VideoChannel | |
25 | ||
26 | constructor ( | |
bce47964 C |
27 | private videoPlaylistService: VideoPlaylistService, |
28 | private videoChannelService: VideoChannelService | |
29 | ) {} | |
30 | ||
31 | ngOnInit () { | |
32 | // Parent get the video channel for us | |
33 | this.videoChannelSub = this.videoChannelService.videoChannelLoaded | |
34 | .subscribe(videoChannel => { | |
35 | this.videoChannel = videoChannel | |
36 | this.loadVideoPlaylists() | |
37 | }) | |
38 | } | |
39 | ||
40 | ngOnDestroy () { | |
41 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() | |
42 | } | |
43 | ||
44 | onNearOfBottom () { | |
c8487f3f | 45 | if (!hasMoreItems(this.pagination)) return |
bce47964 C |
46 | |
47 | this.pagination.currentPage += 1 | |
48 | this.loadVideoPlaylists() | |
49 | } | |
50 | ||
51 | private loadVideoPlaylists () { | |
ad453580 | 52 | this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination) |
bce47964 C |
53 | .subscribe(res => { |
54 | this.videoPlaylists = this.videoPlaylists.concat(res.data) | |
55 | this.pagination.totalItems = res.total | |
ad453580 C |
56 | |
57 | this.onDataSubject.next(res.data) | |
bce47964 C |
58 | }) |
59 | } | |
60 | } |