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