1 import { Subject, Subscription } from 'rxjs'
2 import { Component, OnDestroy, OnInit } from '@angular/core'
3 import { ComponentPagination, hasMoreItems, 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, 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
33 // Parent get the video channel for us
34 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
35 .subscribe(videoChannel => {
36 this.videoChannel = videoChannel
37 this.loadVideoPlaylists()
42 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
46 if (!hasMoreItems(this.pagination)) return
48 this.pagination.currentPage += 1
49 this.loadVideoPlaylists()
53 return this.screenService.isInMobileView()
56 private loadVideoPlaylists () {
57 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
59 this.videoPlaylists = this.videoPlaylists.concat(res.data)
60 this.pagination.totalItems = res.total
62 this.onDataSubject.next(res.data)