1 import { from } from 'rxjs'
2 import { finalize, map, switchMap, tap } from 'rxjs/operators'
3 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
4 import { MarkdownService, Notifier, UserService } from '@app/core'
5 import { FindInBulkService } from '@app/shared/shared-search'
6 import { Video, VideoSortField } from '@shared/models/videos'
7 import { VideoChannel, VideoService } from '../../shared-main'
8 import { CustomMarkupComponent } from './shared'
11 * Markup component that creates a channel miniature only
15 selector: 'my-channel-miniature-markup',
16 templateUrl: 'channel-miniature-markup.component.html',
17 styleUrls: [ 'channel-miniature-markup.component.scss' ]
19 export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, OnInit {
21 @Input() displayLatestVideo: boolean
22 @Input() displayDescription: boolean
24 @Output() loaded = new EventEmitter<boolean>()
27 descriptionHTML: string
32 private markdown: MarkdownService,
33 private findInBulk: FindInBulkService,
34 private videoService: VideoService,
35 private userService: UserService,
36 private notifier: Notifier
40 this.findInBulk.getChannel(this.name)
42 tap(channel => this.channel = channel),
43 switchMap(() => from(this.markdown.textMarkdownToHTML(this.channel.description))),
44 tap(html => this.descriptionHTML = html),
45 switchMap(() => this.loadVideosObservable()),
46 finalize(() => this.loaded.emit(true))
48 ({ total, data }) => {
49 this.totalVideos = total
53 err => this.notifier.error($localize`Error in channel miniature component: ${err.message}`)
57 getVideoChannelLink () {
58 return [ '/c', this.channel.nameWithHost ]
61 private loadVideosObservable () {
62 const videoOptions = {
63 videoChannel: this.channel,
68 sort: '-publishedAt' as VideoSortField,
72 return this.userService.getAnonymousOrLoggedUser()
74 map(user => user.nsfwPolicy),
75 switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))