1 import { Subscription } from 'rxjs'
2 import { first } from 'rxjs/operators'
3 import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'
4 import { ComponentPaginationLight, DisableForReuseHook, HooksService, ScreenService } from '@app/core'
5 import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
6 import { MiniatureDisplayOptions, VideoFilters } from '@app/shared/shared-video-miniature'
7 import { Video, VideoSortField } from '@shared/models'
10 selector: 'my-video-channel-videos',
11 templateUrl: './video-channel-videos.component.html'
13 export class VideoChannelVideosComponent implements OnInit, AfterViewInit, OnDestroy, DisableForReuseHook {
14 getVideosObservableFunction = this.getVideosObservable.bind(this)
15 getSyndicationItemsFunction = this.getSyndicationItems.bind(this)
17 title = $localize`Videos`
18 defaultSort = '-publishedAt' as VideoSortField
20 displayOptions: MiniatureDisplayOptions = {
31 videoChannel: VideoChannel
34 private videoChannelSub: Subscription
37 private screenService: ScreenService,
38 private videoChannelService: VideoChannelService,
39 private videoService: VideoService,
40 private hooks: HooksService
45 // Parent get the video channel for us
46 this.videoChannelService.videoChannelLoaded.pipe(first())
47 .subscribe(videoChannel => {
48 this.videoChannel = videoChannel
50 this.hooks.runAction('action:video-channel-videos.video-channel.loaded', 'video-channel', { videoChannel })
55 this.hooks.runAction('action:video-channel-videos.init', 'video-channel')
59 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
62 getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) {
64 ...filters.toVideosAPIObject(),
66 videoPagination: pagination,
67 videoChannel: this.videoChannel,
71 return this.videoService.getVideoChannelVideos(params)
74 getSyndicationItems () {
75 return this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
79 return this.screenService.isInMobileView()
90 onVideosLoaded (videos: Video[]) {
91 this.hooks.runAction('action:video-channel-videos.videos.loaded', 'video-channel', { videos })