]>
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 { 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' | |
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 | 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.route.data.subscribe(data => { | |
69 | if (!data?.isContact) return | |
70 | ||
71 | const prefill = this.route.snapshot.queryParams | |
72 | ||
73 | this.contactAdminModal.show(prefill) | |
74 | }) | |
75 | ||
76 | this.languages = languages | |
77 | this.categories = categories | |
78 | ||
79 | this.shortDescription = about.instance.shortDescription | |
80 | this.descriptionContent = about.instance.description | |
81 | ||
82 | this.html = await this.instanceService.buildHtml(about) | |
83 | ||
84 | this.initialized = true | |
85 | } | |
86 | ||
87 | ngAfterViewChecked () { | |
88 | if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) { | |
89 | this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) | |
90 | ||
91 | this.lastScrollHash = window.location.hash | |
92 | } | |
93 | } | |
94 | ||
95 | onClickCopyLink (anchor: HTMLAnchorElement) { | |
96 | const link = anchor.href | |
97 | copyToClipboard(link) | |
98 | this.notifier.success(link, $localize `Link copied`) | |
99 | } | |
100 | } |