1 import { Subject, Subscription } from 'rxjs'
2 import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'
3 import { ComponentPagination, hasMoreItems, HooksService, ScreenService } from '@app/core'
4 import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
5 import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
8 selector: 'my-video-channel-playlists',
9 templateUrl: './video-channel-playlists.component.html',
10 styleUrls: [ './video-channel-playlists.component.scss' ]
12 export class VideoChannelPlaylistsComponent implements OnInit, AfterViewInit, OnDestroy {
13 videoPlaylists: VideoPlaylist[] = []
15 pagination: ComponentPagination = {
21 onDataSubject = new Subject<any[]>()
23 private videoChannelSub: Subscription
24 private videoChannel: VideoChannel
27 private videoPlaylistService: VideoPlaylistService,
28 private videoChannelService: VideoChannelService,
29 private screenService: ScreenService,
30 private hooks: HooksService
34 // Parent get the video channel for us
35 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
36 .subscribe(videoChannel => {
37 this.videoChannel = videoChannel
39 this.hooks.runAction('action:video-channel-playlists.video-channel.loaded', 'video-channel', { videoChannel })
41 this.loadVideoPlaylists()
46 this.hooks.runAction('action:video-channel-playlists.init', 'video-channel')
50 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
54 if (!hasMoreItems(this.pagination)) return
56 this.pagination.currentPage += 1
57 this.loadVideoPlaylists()
61 return this.screenService.isInMobileView()
64 private loadVideoPlaylists () {
65 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
67 this.videoPlaylists = this.videoPlaylists.concat(res.data)
68 this.pagination.totalItems = res.total
70 this.hooks.runAction('action:video-channel-playlists.playlists.loaded', 'video-channel', { playlists: this.videoPlaylists })
72 this.onDataSubject.next(res.data)