]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.component.ts
ffb4294abff7e41391442ecf1b471193bfb469fe
[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, ServerService } from '@app/core'
6 import { CustomMarkupService } from '@app/shared/shared-custom-markup'
7 import { InstanceService } from '@app/shared/shared-instance'
8 import { About, HTMLServerConfig, 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
20 shortDescription = ''
21 descriptionContent: string
22
23 html = {
24 terms: '',
25 codeOfConduct: '',
26 moderationInformation: '',
27 administrator: '',
28 creationReason: '',
29 maintenanceLifetime: '',
30 businessModel: '',
31 hardwareInformation: ''
32 }
33
34 languages: string[] = []
35 categories: string[] = []
36
37 initialized = false
38
39 private serverConfig: HTMLServerConfig
40
41 private lastScrollHash: string
42
43 constructor (
44 private viewportScroller: ViewportScroller,
45 private route: ActivatedRoute,
46 private notifier: Notifier,
47 private serverService: ServerService,
48 private instanceService: InstanceService
49 ) {}
50
51 get instanceName () {
52 return this.serverConfig.instance.name
53 }
54
55 get isContactFormEnabled () {
56 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
57 }
58
59 get isNSFW () {
60 return this.serverConfig.instance.isNSFW
61 }
62
63 async ngOnInit () {
64 const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
65
66 this.serverConfig = this.serverService.getHTMLConfig()
67
68 this.languages = languages
69 this.categories = categories
70
71 this.shortDescription = about.instance.shortDescription
72 this.descriptionContent = about.instance.description
73
74 this.html = await this.instanceService.buildHtml(about)
75
76 this.initialized = true
77 }
78
79 ngAfterViewChecked () {
80 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
81 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
82
83 this.lastScrollHash = window.location.hash
84 }
85 }
86
87 onClickCopyLink (anchor: HTMLAnchorElement) {
88 const link = anchor.href
89 copyToClipboard(link)
90 this.notifier.success(link, $localize `Link copied`)
91 }
92 }