1 import { from } from 'rxjs'
2 import { finalize, map, switchMap, tap } from 'rxjs/operators'
3 import { ChangeDetectionStrategy, ChangeDetectorRef, 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 { VideoSortField } from '@shared/models'
7 import { Video, 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' ],
18 changeDetection: ChangeDetectionStrategy.OnPush
20 export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, OnInit {
22 @Input() displayLatestVideo: boolean
23 @Input() displayDescription: boolean
25 @Output() loaded = new EventEmitter<boolean>()
28 descriptionHTML: string
33 private markdown: MarkdownService,
34 private findInBulk: FindInBulkService,
35 private videoService: VideoService,
36 private userService: UserService,
37 private notifier: Notifier,
38 private cd: ChangeDetectorRef
42 this.findInBulk.getChannel(this.name)
45 this.channel = channel
47 switchMap(() => from(this.markdown.textMarkdownToHTML({
48 markdown: this.channel.description,
53 this.descriptionHTML = html
55 switchMap(() => this.loadVideosObservable()),
56 finalize(() => this.loaded.emit(true))
58 next: ({ total, data }) => {
59 this.totalVideos = total
62 this.cd.markForCheck()
65 error: err => this.notifier.error($localize`Error in channel miniature component: ${err.message}`)
69 getVideoChannelLink () {
70 return [ '/c', this.channel.nameWithHost ]
73 private loadVideosObservable () {
74 const videoOptions = {
75 videoChannel: this.channel,
80 sort: '-publishedAt' as VideoSortField,
84 return this.userService.getAnonymousOrLoggedUser()
86 map(user => user.nsfwPolicy),
87 switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))