1 import { map, switchMap } from 'rxjs/operators'
2 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
3 import { MarkdownService, UserService } from '@app/core'
4 import { Video, VideoSortField } from '@shared/models/videos'
5 import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main'
6 import { CustomMarkupComponent } from './shared'
9 * Markup component that creates a channel miniature only
13 selector: 'my-channel-miniature-markup',
14 templateUrl: 'channel-miniature-markup.component.html',
15 styleUrls: [ 'channel-miniature-markup.component.scss' ]
17 export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, OnInit {
19 @Input() displayLatestVideo: boolean
20 @Input() displayDescription: boolean
22 @Output() loaded = new EventEmitter<boolean>()
25 descriptionHTML: string
30 private markdown: MarkdownService,
31 private channelService: VideoChannelService,
32 private videoService: VideoService,
33 private userService: UserService
37 this.channelService.getVideoChannel(this.name)
38 .subscribe(async channel => {
39 this.channel = channel
41 this.descriptionHTML = await this.markdown.textMarkdownToHTML(channel.description)
47 getVideoChannelLink () {
48 return [ '/c', this.channel.nameWithHost ]
51 private loadVideos () {
52 const videoOptions = {
53 videoChannel: this.channel,
58 sort: '-publishedAt' as VideoSortField,
62 this.userService.getAnonymousOrLoggedUser()
64 map(user => user.nsfwPolicy),
65 switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
68 next: ({ total, data }) => {
69 this.totalVideos = total
73 complete: () => this.loaded.emit(true)