1 import { Component, EventEmitter, Inject, Input, LOCALE_ID, OnChanges, Output } from '@angular/core'
2 import { MarkdownService, Notifier } from '@app/core'
3 import { VideoDetails, VideoService } from '@app/shared/shared-main'
6 selector: 'my-video-description',
7 templateUrl: './video-description.component.html',
8 styleUrls: [ './video-description.component.scss' ]
10 export class VideoDescriptionComponent implements OnChanges {
11 @Input() video: VideoDetails
13 @Output() timestampClicked = new EventEmitter<number>()
15 descriptionLoading = false
16 completeDescriptionShown = false
17 completeVideoDescription: string
18 shortVideoDescription: string
19 videoHTMLDescription = ''
22 private videoService: VideoService,
23 private notifier: Notifier,
24 private markdownService: MarkdownService,
25 @Inject(LOCALE_ID) private localeId: string
29 this.descriptionLoading = false
30 this.completeDescriptionShown = false
31 this.completeVideoDescription = undefined
33 this.setVideoDescriptionHTML()
36 showMoreDescription () {
37 if (this.completeVideoDescription === undefined) {
38 return this.loadCompleteDescription()
41 this.updateVideoDescription(this.completeVideoDescription)
42 this.completeDescriptionShown = true
45 showLessDescription () {
46 this.updateVideoDescription(this.shortVideoDescription)
47 this.completeDescriptionShown = false
50 loadCompleteDescription () {
51 this.descriptionLoading = true
53 this.videoService.loadCompleteDescription(this.video.descriptionPath)
56 this.completeDescriptionShown = true
57 this.descriptionLoading = false
59 this.shortVideoDescription = this.video.description
60 this.completeVideoDescription = description
62 this.updateVideoDescription(this.completeVideoDescription)
66 this.descriptionLoading = false
67 this.notifier.error(error.message)
72 onTimestampClicked (timestamp: number) {
73 this.timestampClicked.emit(timestamp)
76 private updateVideoDescription (description: string) {
77 this.video.description = description
78 this.setVideoDescriptionHTML()
79 .catch(err => console.error(err))
82 private async setVideoDescriptionHTML () {
83 const html = await this.markdownService.textMarkdownToHTML(this.video.description)
84 this.videoHTMLDescription = this.markdownService.processVideoTimestamps(html)