]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts
Merge remote-tracking branch 'origin/pr/1785' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-playlists / video-channel-playlists.component.ts
CommitLineData
bce47964 1import { Component, OnDestroy, OnInit } from '@angular/core'
bce47964
C
2import { ConfirmService } from '../../core/confirm'
3import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
4import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
bce47964
C
5import { Subscription } from 'rxjs'
6import { Notifier } from '@app/core'
7import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
8import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
9import { 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})
16export 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 (
bce47964
C
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 // Last page
50 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
51
52 this.pagination.currentPage += 1
53 this.loadVideoPlaylists()
54 }
55
56 private loadVideoPlaylists () {
1acd784c 57 this.videoPlaylistService.listChannelPlaylists(this.videoChannel)
bce47964
C
58 .subscribe(res => {
59 this.videoPlaylists = this.videoPlaylists.concat(res.data)
60 this.pagination.totalItems = res.total
61 })
62 }
63}