]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { ViewportScroller } from '@angular/common' |
2 | import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core' | |
3 | import { ActivatedRoute } from '@angular/router' | |
d3e56c0c | 4 | import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component' |
f3081d64 | 5 | import { Notifier } from '@app/core' |
5beb89f2 | 6 | import { copyToClipboard } from '../../../root-helpers/utils' |
67ed6552 | 7 | import { InstanceService } from '@app/shared/shared-instance' |
ba430d75 | 8 | import { ServerConfig } from '@shared/models' |
b42f9c40 | 9 | import { ResolverData } from './about-instance.resolver' |
36f9424f C |
10 | |
11 | @Component({ | |
78f912ed C |
12 | selector: 'my-about-instance', |
13 | templateUrl: './about-instance.component.html', | |
14 | styleUrls: [ './about-instance.component.scss' ] | |
36f9424f | 15 | }) |
45e0d669 | 16 | export class AboutInstanceComponent implements OnInit, AfterViewChecked { |
f36da21e | 17 | @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent |
d3e56c0c | 18 | |
45c0fb35 | 19 | shortDescription = '' |
ccc00cb2 C |
20 | |
21 | html = { | |
22 | description: '', | |
23 | terms: '', | |
24 | codeOfConduct: '', | |
25 | moderationInformation: '', | |
be04c6fd C |
26 | administrator: '', |
27 | hardwareInformation: '' | |
ccc00cb2 C |
28 | } |
29 | ||
8ae03c37 | 30 | creationReason = '' |
ccc00cb2 C |
31 | maintenanceLifetime = '' |
32 | businessModel = '' | |
33 | ||
34 | languages: string[] = [] | |
4402b54d | 35 | categories: string[] = [] |
36f9424f | 36 | |
ba430d75 C |
37 | serverConfig: ServerConfig |
38 | ||
12c8a463 C |
39 | initialized = false |
40 | ||
64e0f8cf C |
41 | private lastScrollHash: string |
42 | ||
36f9424f | 43 | constructor ( |
45e0d669 | 44 | private viewportScroller: ViewportScroller, |
b42f9c40 | 45 | private route: ActivatedRoute, |
f3081d64 | 46 | private notifier: Notifier, |
b42f9c40 | 47 | private instanceService: InstanceService |
36f9424f C |
48 | ) {} |
49 | ||
50 | get instanceName () { | |
ba430d75 | 51 | return this.serverConfig.instance.name |
36f9424f C |
52 | } |
53 | ||
d3e56c0c | 54 | get isContactFormEnabled () { |
ba430d75 | 55 | return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled |
d3e56c0c C |
56 | } |
57 | ||
c8000975 | 58 | get isNSFW () { |
ba430d75 | 59 | return this.serverConfig.instance.isNSFW |
c8000975 C |
60 | } |
61 | ||
b42f9c40 | 62 | async ngOnInit () { |
12c8a463 | 63 | const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData |
ba430d75 | 64 | |
12c8a463 | 65 | this.serverConfig = serverConfig |
b42f9c40 C |
66 | |
67 | this.languages = languages | |
68 | this.categories = categories | |
69 | ||
70 | this.shortDescription = about.instance.shortDescription | |
71 | ||
72 | this.creationReason = about.instance.creationReason | |
73 | this.maintenanceLifetime = about.instance.maintenanceLifetime | |
74 | this.businessModel = about.instance.businessModel | |
75 | ||
76 | this.html = await this.instanceService.buildHtml(about) | |
12c8a463 C |
77 | |
78 | this.initialized = true | |
36f9424f C |
79 | } |
80 | ||
45e0d669 | 81 | ngAfterViewChecked () { |
12c8a463 | 82 | if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) { |
64e0f8cf C |
83 | this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) |
84 | ||
85 | this.lastScrollHash = window.location.hash | |
86 | } | |
45e0d669 RK |
87 | } |
88 | ||
d3e56c0c C |
89 | openContactModal () { |
90 | return this.contactAdminModal.show() | |
91 | } | |
f3081d64 K |
92 | |
93 | onClickCopyLink (anchor: HTMLAnchorElement) { | |
94 | const link = anchor.href | |
95 | copyToClipboard(link) | |
96 | this.notifier.success(link, $localize `Link copied`) | |
97 | } | |
36f9424f | 98 | } |