]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts
7990044a2baababf4c830c895eeb2552c05e9b12
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-playlists / video-channel-playlists.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ConfirmService } from '../../core/confirm'
3 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
4 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
5 import { Subscription } from 'rxjs'
6 import { Notifier } from '@app/core'
7 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
8 import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
9 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
10
11 @Component({
12 selector: 'my-video-channel-playlists',
13 templateUrl: './video-channel-playlists.component.html',
14 styleUrls: [ './video-channel-playlists.component.scss' ]
15 })
16 export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy {
17 videoPlaylists: VideoPlaylist[] = []
18
19 pagination: ComponentPagination = {
20 currentPage: 1,
21 itemsPerPage: 20,
22 totalItems: null
23 }
24
25 private videoChannelSub: Subscription
26 private videoChannel: VideoChannel
27
28 constructor (
29 private notifier: Notifier,
30 private confirmService: ConfirmService,
31 private videoPlaylistService: VideoPlaylistService,
32 private videoChannelService: VideoChannelService
33 ) {}
34
35 ngOnInit () {
36 // Parent get the video channel for us
37 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
38 .subscribe(videoChannel => {
39 this.videoChannel = videoChannel
40 this.loadVideoPlaylists()
41 })
42 }
43
44 ngOnDestroy () {
45 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
46 }
47
48 onNearOfBottom () {
49 if (!hasMoreItems(this.pagination)) return
50
51 this.pagination.currentPage += 1
52 this.loadVideoPlaylists()
53 }
54
55 private loadVideoPlaylists () {
56 this.videoPlaylistService.listChannelPlaylists(this.videoChannel)
57 .subscribe(res => {
58 this.videoPlaylists = this.videoPlaylists.concat(res.data)
59 this.pagination.totalItems = res.total
60 })
61 }
62 }