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 { AboutHTML } 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 descriptionElement: HTMLDivElement
23 languages: string[] = []
24 categories: string[] = []
29 private serverConfig: HTMLServerConfig
31 private lastScrollHash: string
34 private viewportScroller: ViewportScroller,
35 private route: ActivatedRoute,
36 private notifier: Notifier,
37 private serverService: ServerService
41 return this.serverConfig.instance.name
44 get isContactFormEnabled () {
45 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
49 return this.serverConfig.instance.isNSFW
53 const { about, languages, categories, aboutHTML, descriptionElement }: ResolverData = this.route.snapshot.data.instanceData
55 this.aboutHTML = aboutHTML
56 this.descriptionElement = descriptionElement
58 this.languages = languages
59 this.categories = categories
61 this.shortDescription = about.instance.shortDescription
63 this.serverConfig = this.serverService.getHTMLConfig()
65 this.route.data.subscribe(data => {
66 if (!data?.isContact) return
68 const prefill = this.route.snapshot.queryParams
70 this.contactAdminModal.show(prefill)
73 this.initialized = true
76 ngAfterViewChecked () {
77 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
78 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
80 this.lastScrollHash = window.location.hash
84 onClickCopyLink (anchor: HTMLAnchorElement) {
85 const link = anchor.href
87 this.notifier.success(link, $localize`Link copied`)