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, ServerStats } 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 serverStats: ServerStats
31 private serverConfig: HTMLServerConfig
33 private lastScrollHash: string
36 private viewportScroller: ViewportScroller,
37 private route: ActivatedRoute,
38 private notifier: Notifier,
39 private serverService: ServerService
43 return this.serverConfig.instance.name
46 get isContactFormEnabled () {
47 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
51 return this.serverConfig.instance.isNSFW
55 const { about, languages, categories, aboutHTML, descriptionElement, serverStats }: ResolverData = this.route.snapshot.data.instanceData
57 this.serverStats = serverStats
59 this.aboutHTML = aboutHTML
60 this.descriptionElement = descriptionElement
62 this.languages = languages
63 this.categories = categories
65 this.shortDescription = about.instance.shortDescription
67 this.serverConfig = this.serverService.getHTMLConfig()
69 this.route.data.subscribe(data => {
70 if (!data?.isContact) return
72 const prefill = this.route.snapshot.queryParams
74 this.contactAdminModal.show(prefill)
77 this.initialized = true
80 ngAfterViewChecked () {
81 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
82 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
84 this.lastScrollHash = window.location.hash
88 onClickCopyLink (anchor: HTMLAnchorElement) {
89 const link = anchor.href
91 this.notifier.success(link, $localize`Link copied`)