]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-playlists/video-channel-playlists.component.ts
Add channel hooks
[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 { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'
3 import { ComponentPagination, hasMoreItems, HooksService, 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, AfterViewInit, 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 private hooks: HooksService
31 ) {}
32
33 ngOnInit () {
34 // Parent get the video channel for us
35 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
36 .subscribe(videoChannel => {
37 this.videoChannel = videoChannel
38
39 this.hooks.runAction('action:video-channel-playlists.video-channel.loaded', 'video-channel', { videoChannel })
40
41 this.loadVideoPlaylists()
42 })
43 }
44
45 ngAfterViewInit () {
46 this.hooks.runAction('action:video-channel-playlists.init', 'video-channel')
47 }
48
49 ngOnDestroy () {
50 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
51 }
52
53 onNearOfBottom () {
54 if (!hasMoreItems(this.pagination)) return
55
56 this.pagination.currentPage += 1
57 this.loadVideoPlaylists()
58 }
59
60 displayAsRow () {
61 return this.screenService.isInMobileView()
62 }
63
64 private loadVideoPlaylists () {
65 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
66 .subscribe(res => {
67 this.videoPlaylists = this.videoPlaylists.concat(res.data)
68 this.pagination.totalItems = res.total
69
70 this.hooks.runAction('action:video-channel-playlists.playlists.loaded', 'video-channel', { playlists: this.videoPlaylists })
71
72 this.onDataSubject.next(res.data)
73 })
74 }
75 }