]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts
14465bb8dd6947b52816a560b54c3eacfd0b402b
[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, ScreenService } 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 private screenService: ScreenService
30 ) {}
31
32 ngOnInit () {
33 // Parent get the video channel for us
34 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
35 .subscribe(videoChannel => {
36 this.videoChannel = videoChannel
37 this.loadVideoPlaylists()
38 })
39 }
40
41 ngOnDestroy () {
42 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
43 }
44
45 onNearOfBottom () {
46 if (!hasMoreItems(this.pagination)) return
47
48 this.pagination.currentPage += 1
49 this.loadVideoPlaylists()
50 }
51
52 displayAsRow () {
53 return this.screenService.isInMobileView()
54 }
55
56 private loadVideoPlaylists () {
57 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
58 .subscribe(res => {
59 this.videoPlaylists = this.videoPlaylists.concat(res.data)
60 this.pagination.totalItems = res.total
61
62 this.onDataSubject.next(res.data)
63 })
64 }
65 }