aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+video-channels/video-channel-about/video-channel-about.component.ts
blob: 19e4bc1f45be9ef3da170d8ec997ca83bb674dad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Subscription } from 'rxjs'
import { Component, OnDestroy, OnInit } from '@angular/core'
import { MarkdownService } from '@app/core'
import { VideoChannel, VideoChannelService } from '@app/shared/shared-main'
import { I18n } from '@ngx-translate/i18n-polyfill'

@Component({
  selector: 'my-video-channel-about',
  templateUrl: './video-channel-about.component.html',
  styleUrls: [ './video-channel-about.component.scss' ]
})
export class VideoChannelAboutComponent implements OnInit, OnDestroy {
  videoChannel: VideoChannel
  descriptionHTML = ''
  supportHTML = ''

  private videoChannelSub: Subscription

  constructor (
    private i18n: I18n,
    private videoChannelService: VideoChannelService,
    private markdownService: MarkdownService
  ) { }

  ngOnInit () {
    // Parent get the video channel for us
    this.videoChannelSub = this.videoChannelService.videoChannelLoaded
      .subscribe(async videoChannel => {
        this.videoChannel = videoChannel

        this.descriptionHTML = await this.markdownService.textMarkdownToHTML(this.videoChannel.description)
        this.supportHTML = await this.markdownService.enhancedMarkdownToHTML(this.videoChannel.support)
      })
  }

  ngOnDestroy () {
    if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
  }

  getVideoChannelDescription () {
    if (this.descriptionHTML) return this.descriptionHTML

    return this.i18n('No description')
  }
}