1 import { Subject, Subscription } from 'rxjs'
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'
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
32 // Parent get the video channel for us
33 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
34 .subscribe(videoChannel => {
35 this.videoChannel = videoChannel
36 this.loadVideoPlaylists()
41 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
45 if (!hasMoreItems(this.pagination)) return
47 this.pagination.currentPage += 1
48 this.loadVideoPlaylists()
51 private loadVideoPlaylists () {
52 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
54 this.videoPlaylists = this.videoPlaylists.concat(res.data)
55 this.pagination.totalItems = res.total
57 this.onDataSubject.next(res.data)