1 import { map, switchMap } from 'rxjs/operators'
2 import { Component, Input, OnInit } 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'
8 * Markup component that creates a channel miniature only
12 selector: 'my-channel-miniature-markup',
13 templateUrl: 'channel-miniature-markup.component.html',
14 styleUrls: [ 'channel-miniature-markup.component.scss' ]
16 export class ChannelMiniatureMarkupComponent implements OnInit {
18 @Input() displayLatestVideo: boolean
19 @Input() displayDescription: boolean
22 descriptionHTML: string
27 private markdown: MarkdownService,
28 private channelService: VideoChannelService,
29 private videoService: VideoService,
30 private userService: UserService
34 this.channelService.getVideoChannel(this.name)
35 .subscribe(async channel => {
36 this.channel = channel
38 this.descriptionHTML = await this.markdown.textMarkdownToHTML(channel.description)
44 getVideoChannelLink () {
45 return [ '/c', this.channel.nameWithHost ]
48 private loadVideos () {
49 const videoOptions = {
50 videoChannel: this.channel,
55 sort: '-publishedAt' as VideoSortField,
59 this.userService.getAnonymousOrLoggedUser()
61 map(user => user.nsfwPolicy),
62 switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
64 .subscribe(({ total, data }) => {
65 this.totalVideos = total