]>
Commit | Line | Data |
---|---|---|
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' | |
10 | ||
11 | @Component({ | |
12 | selector: 'my-about-instance', | |
13 | templateUrl: './about-instance.component.html', | |
14 | styleUrls: [ './about-instance.component.scss' ] | |
15 | }) | |
16 | export class AboutInstanceComponent implements OnInit, AfterViewChecked { | |
17 | @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement> | |
18 | @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent | |
19 | ||
20 | aboutHTML: AboutHTML | |
21 | descriptionElement: HTMLDivElement | |
22 | ||
23 | languages: string[] = [] | |
24 | categories: string[] = [] | |
25 | shortDescription = '' | |
26 | ||
27 | initialized = false | |
28 | ||
29 | private serverConfig: HTMLServerConfig | |
30 | ||
31 | private lastScrollHash: string | |
32 | ||
33 | constructor ( | |
34 | private viewportScroller: ViewportScroller, | |
35 | private route: ActivatedRoute, | |
36 | private notifier: Notifier, | |
37 | private serverService: ServerService | |
38 | ) {} | |
39 | ||
40 | get instanceName () { | |
41 | return this.serverConfig.instance.name | |
42 | } | |
43 | ||
44 | get isContactFormEnabled () { | |
45 | return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled | |
46 | } | |
47 | ||
48 | get isNSFW () { | |
49 | return this.serverConfig.instance.isNSFW | |
50 | } | |
51 | ||
52 | ngOnInit () { | |
53 | const { about, languages, categories, aboutHTML, descriptionElement }: ResolverData = this.route.snapshot.data.instanceData | |
54 | ||
55 | this.aboutHTML = aboutHTML | |
56 | this.descriptionElement = descriptionElement | |
57 | ||
58 | this.languages = languages | |
59 | this.categories = categories | |
60 | ||
61 | this.shortDescription = about.instance.shortDescription | |
62 | ||
63 | this.serverConfig = this.serverService.getHTMLConfig() | |
64 | ||
65 | this.route.data.subscribe(data => { | |
66 | if (!data?.isContact) return | |
67 | ||
68 | const prefill = this.route.snapshot.queryParams | |
69 | ||
70 | this.contactAdminModal.show(prefill) | |
71 | }) | |
72 | ||
73 | this.initialized = true | |
74 | } | |
75 | ||
76 | ngAfterViewChecked () { | |
77 | if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) { | |
78 | this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) | |
79 | ||
80 | this.lastScrollHash = window.location.hash | |
81 | } | |
82 | } | |
83 | ||
84 | onClickCopyLink (anchor: HTMLAnchorElement) { | |
85 | const link = anchor.href | |
86 | copyToClipboard(link) | |
87 | this.notifier.success(link, $localize`Link copied`) | |
88 | } | |
89 | } |