]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts
Reorganize client shared modules
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-playlists / video-channel-playlists.component.ts
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'
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
21 onDataSubject = new Subject<any[]>()
22
23 private videoChannelSub: Subscription
24 private videoChannel: VideoChannel
25
26 constructor (
27 private videoPlaylistService: VideoPlaylistService,
28 private videoChannelService: VideoChannelService
29 ) {}
30
31 ngOnInit () {
32 // Parent get the video channel for us
33 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
34 .subscribe(videoChannel => {
35 this.videoChannel = videoChannel
36 this.loadVideoPlaylists()
37 })
38 }
39
40 ngOnDestroy () {
41 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
42 }
43
44 onNearOfBottom () {
45 if (!hasMoreItems(this.pagination)) return
46
47 this.pagination.currentPage += 1
48 this.loadVideoPlaylists()
49 }
50
51 private loadVideoPlaylists () {
52 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
53 .subscribe(res => {
54 this.videoPlaylists = this.videoPlaylists.concat(res.data)
55 this.pagination.totalItems = res.total
56
57 this.onDataSubject.next(res.data)
58 })
59 }
60 }