]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-instance/about-instance.component.ts
Add ability to set custom markdown in description
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
CommitLineData
67ed6552 1import { ViewportScroller } from '@angular/common'
8ee25e17 2import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
67ed6552 3import { ActivatedRoute } from '@angular/router'
d3e56c0c 4import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component'
f3081d64 5import { Notifier } from '@app/core'
8ee25e17 6import { CustomMarkupService } from '@app/shared/shared-custom-markup'
67ed6552 7import { InstanceService } from '@app/shared/shared-instance'
8ee25e17
C
8import { About, ServerConfig } from '@shared/models'
9import { copyToClipboard } from '../../../root-helpers/utils'
b42f9c40 10import { ResolverData } from './about-instance.resolver'
36f9424f
C
11
12@Component({
78f912ed
C
13 selector: 'my-about-instance',
14 templateUrl: './about-instance.component.html',
15 styleUrls: [ './about-instance.component.scss' ]
36f9424f 16})
45e0d669 17export class AboutInstanceComponent implements OnInit, AfterViewChecked {
8ee25e17 18 @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
f36da21e 19 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
d3e56c0c 20
45c0fb35 21 shortDescription = ''
8ee25e17 22 descriptionContent: string
ccc00cb2
C
23
24 html = {
ccc00cb2
C
25 terms: '',
26 codeOfConduct: '',
27 moderationInformation: '',
be04c6fd 28 administrator: '',
f45c7cc7
FC
29 creationReason: '',
30 maintenanceLifetime: '',
31 businessModel: '',
be04c6fd 32 hardwareInformation: ''
ccc00cb2
C
33 }
34
ccc00cb2 35 languages: string[] = []
4402b54d 36 categories: string[] = []
36f9424f 37
ba430d75
C
38 serverConfig: ServerConfig
39
12c8a463
C
40 initialized = false
41
64e0f8cf
C
42 private lastScrollHash: string
43
36f9424f 44 constructor (
8ee25e17 45 private customMarkupService: CustomMarkupService,
45e0d669 46 private viewportScroller: ViewportScroller,
b42f9c40 47 private route: ActivatedRoute,
f3081d64 48 private notifier: Notifier,
b42f9c40 49 private instanceService: InstanceService
36f9424f
C
50 ) {}
51
52 get instanceName () {
ba430d75 53 return this.serverConfig.instance.name
36f9424f
C
54 }
55
d3e56c0c 56 get isContactFormEnabled () {
ba430d75 57 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
d3e56c0c
C
58 }
59
c8000975 60 get isNSFW () {
ba430d75 61 return this.serverConfig.instance.isNSFW
c8000975
C
62 }
63
b42f9c40 64 async ngOnInit () {
12c8a463 65 const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData
ba430d75 66
12c8a463 67 this.serverConfig = serverConfig
b42f9c40
C
68
69 this.languages = languages
70 this.categories = categories
71
72 this.shortDescription = about.instance.shortDescription
8ee25e17 73 this.descriptionContent = about.instance.description
b42f9c40 74
b42f9c40 75 this.html = await this.instanceService.buildHtml(about)
12c8a463 76
8ee25e17
C
77 await this.injectDescription(about)
78
12c8a463 79 this.initialized = true
36f9424f
C
80 }
81
45e0d669 82 ngAfterViewChecked () {
12c8a463 83 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
64e0f8cf
C
84 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
85
86 this.lastScrollHash = window.location.hash
87 }
45e0d669
RK
88 }
89
d3e56c0c
C
90 openContactModal () {
91 return this.contactAdminModal.show()
92 }
f3081d64
K
93
94 onClickCopyLink (anchor: HTMLAnchorElement) {
95 const link = anchor.href
96 copyToClipboard(link)
97 this.notifier.success(link, $localize `Link copied`)
98 }
8ee25e17
C
99
100 private async injectDescription (about: About) {
101 const element = await this.customMarkupService.buildElement(about.instance.description)
102
103 this.descriptionWrapper.nativeElement.appendChild(element)
104 }
36f9424f 105}