]>
Commit | Line | Data |
---|---|---|
ad453580 | 1 | import { Subject, Subscription } from 'rxjs' |
67ed6552 | 2 | import { Component, OnDestroy, OnInit } from '@angular/core' |
0f7407d9 | 3 | import { ComponentPagination, hasMoreItems, ScreenService } from '@app/core' |
67ed6552 C |
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 | 27 | private videoPlaylistService: VideoPlaylistService, |
0f7407d9 C |
28 | private videoChannelService: VideoChannelService, |
29 | private screenService: ScreenService | |
bce47964 C |
30 | ) {} |
31 | ||
32 | ngOnInit () { | |
33 | // Parent get the video channel for us | |
34 | this.videoChannelSub = this.videoChannelService.videoChannelLoaded | |
35 | .subscribe(videoChannel => { | |
36 | this.videoChannel = videoChannel | |
37 | this.loadVideoPlaylists() | |
38 | }) | |
39 | } | |
40 | ||
41 | ngOnDestroy () { | |
42 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() | |
43 | } | |
44 | ||
45 | onNearOfBottom () { | |
c8487f3f | 46 | if (!hasMoreItems(this.pagination)) return |
bce47964 C |
47 | |
48 | this.pagination.currentPage += 1 | |
49 | this.loadVideoPlaylists() | |
50 | } | |
51 | ||
0f7407d9 C |
52 | displayAsRow () { |
53 | return this.screenService.isInMobileView() | |
54 | } | |
55 | ||
bce47964 | 56 | private loadVideoPlaylists () { |
ad453580 | 57 | this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination) |
bce47964 C |
58 | .subscribe(res => { |
59 | this.videoPlaylists = this.videoPlaylists.concat(res.data) | |
60 | this.pagination.totalItems = res.total | |
ad453580 C |
61 | |
62 | this.onDataSubject.next(res.data) | |
bce47964 C |
63 | }) |
64 | } | |
65 | } |