]>
Commit | Line | Data |
---|---|---|
1 | import { ViewportScroller } from '@angular/common' | |
2 | import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core' | |
3 | import { ActivatedRoute } from '@angular/router' | |
4 | import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component' | |
5 | import { Notifier } from '@app/core' | |
6 | import { copyToClipboard } from '../../../root-helpers/utils' | |
7 | import { InstanceService } from '@app/shared/shared-instance' | |
8 | import { ServerConfig } from '@shared/models' | |
9 | import { ResolverData } from './about-instance.resolver' | |
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('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent | |
18 | ||
19 | shortDescription = '' | |
20 | ||
21 | html = { | |
22 | description: '', | |
23 | terms: '', | |
24 | codeOfConduct: '', | |
25 | moderationInformation: '', | |
26 | administrator: '', | |
27 | creationReason: '', | |
28 | maintenanceLifetime: '', | |
29 | businessModel: '', | |
30 | hardwareInformation: '' | |
31 | } | |
32 | ||
33 | languages: string[] = [] | |
34 | categories: string[] = [] | |
35 | ||
36 | serverConfig: ServerConfig | |
37 | ||
38 | initialized = false | |
39 | ||
40 | private lastScrollHash: string | |
41 | ||
42 | constructor ( | |
43 | private viewportScroller: ViewportScroller, | |
44 | private route: ActivatedRoute, | |
45 | private notifier: Notifier, | |
46 | private instanceService: InstanceService | |
47 | ) {} | |
48 | ||
49 | get instanceName () { | |
50 | return this.serverConfig.instance.name | |
51 | } | |
52 | ||
53 | get isContactFormEnabled () { | |
54 | return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled | |
55 | } | |
56 | ||
57 | get isNSFW () { | |
58 | return this.serverConfig.instance.isNSFW | |
59 | } | |
60 | ||
61 | async ngOnInit () { | |
62 | const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData | |
63 | ||
64 | this.serverConfig = serverConfig | |
65 | ||
66 | this.languages = languages | |
67 | this.categories = categories | |
68 | ||
69 | this.shortDescription = about.instance.shortDescription | |
70 | ||
71 | this.html = await this.instanceService.buildHtml(about) | |
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 | openContactModal () { | |
85 | return this.contactAdminModal.show() | |
86 | } | |
87 | ||
88 | onClickCopyLink (anchor: HTMLAnchorElement) { | |
89 | const link = anchor.href | |
90 | copyToClipboard(link) | |
91 | this.notifier.success(link, $localize `Link copied`) | |
92 | } | |
93 | } |