1 import { ViewportScroller } from '@angular/common'
2 import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
3 import { ActivatedRoute } from '@angular/router'
4 import { Notifier, ServerService } from '@app/core'
5 import { InstanceService } from '@app/shared/shared-instance'
6 import { copyToClipboard } from '@root-helpers/utils'
7 import { HTMLServerConfig } from '@shared/models/server'
8 import { ResolverData } from './about-instance.resolver'
9 import { ContactAdminModalComponent } from './contact-admin-modal.component'
12 selector: 'my-about-instance',
13 templateUrl: './about-instance.component.html',
14 styleUrls: [ './about-instance.component.scss' ]
16 export class AboutInstanceComponent implements OnInit, AfterViewChecked {
17 @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
18 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
21 descriptionContent: string
26 moderationInformation: '',
29 maintenanceLifetime: '',
31 hardwareInformation: ''
34 languages: string[] = []
35 categories: string[] = []
39 private serverConfig: HTMLServerConfig
41 private lastScrollHash: string
44 private viewportScroller: ViewportScroller,
45 private route: ActivatedRoute,
46 private notifier: Notifier,
47 private serverService: ServerService,
48 private instanceService: InstanceService
52 return this.serverConfig.instance.name
55 get isContactFormEnabled () {
56 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
60 return this.serverConfig.instance.isNSFW
64 const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
66 this.serverConfig = this.serverService.getHTMLConfig()
68 this.route.data.subscribe(data => {
69 if (!data?.isContact) return
71 const prefill = this.route.snapshot.queryParams
73 this.contactAdminModal.show(prefill)
76 this.languages = languages
77 this.categories = categories
79 this.shortDescription = about.instance.shortDescription
80 this.descriptionContent = about.instance.description
82 this.html = await this.instanceService.buildHtml(about)
84 this.initialized = true
87 ngAfterViewChecked () {
88 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
89 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
91 this.lastScrollHash = window.location.hash
95 onClickCopyLink (anchor: HTMLAnchorElement) {
96 const link = anchor.href
98 this.notifier.success(link, $localize `Link copied`)