1 import { finalize } from 'rxjs/operators'
2 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
3 import { AuthService, Notifier } from '@app/core'
4 import { VideoSortField } from '@shared/models'
5 import { Video, VideoService } from '../../shared-main'
6 import { MiniatureDisplayOptions } from '../../shared-video-miniature'
7 import { CustomMarkupComponent } from './shared'
10 * Markup component list videos depending on criterias
14 selector: 'my-videos-list-markup',
15 templateUrl: 'videos-list-markup.component.html',
16 styleUrls: [ 'videos-list-markup.component.scss' ]
18 export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit {
20 @Input() categoryOneOf: number[]
21 @Input() languageOneOf: string[]
22 @Input() count: number
23 @Input() onlyDisplayTitle: boolean
24 @Input() isLocal: boolean
25 @Input() isLive: boolean
26 @Input() maxRows: number
27 @Input() channelHandle: string
28 @Input() accountHandle: string
30 @Output() loaded = new EventEmitter<boolean>()
34 displayOptions: MiniatureDisplayOptions = {
46 private auth: AuthService,
47 private videoService: VideoService,
48 private notifier: Notifier
52 return this.auth.getUser()
56 if (this.maxRows <= 0) return {}
59 'grid-template-rows': `repeat(${this.maxRows}, 1fr)`,
60 'grid-auto-rows': '0', // Set height to 0 for autogenerated grid rows
61 'overflow-y': 'hidden' // Hide grid items that overflow
66 if (this.onlyDisplayTitle) {
67 for (const key of Object.keys(this.displayOptions)) {
68 this.displayOptions[key] = false
72 return this.getVideosObservable()
73 .pipe(finalize(() => this.loaded.emit(true)))
75 next: ({ data }) => this.videos = data,
77 error: err => this.notifier.error($localize`Error in videos list component: ${err.message}`)
81 getVideosObservable () {
85 itemsPerPage: this.count
87 categoryOneOf: this.categoryOneOf,
88 languageOneOf: this.languageOneOf,
89 isLocal: this.isLocal,
91 sort: this.sort as VideoSortField,
92 account: { nameWithHost: this.accountHandle },
93 videoChannel: { nameWithHost: this.channelHandle }
96 if (this.channelHandle) return this.videoService.getVideoChannelVideos(options)
97 if (this.accountHandle) return this.videoService.getAccountVideos(options)
99 return this.videoService.getVideos(options)