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