]>
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 | 26 | administrator: '', |
f45c7cc7 FC |
27 | creationReason: '', |
28 | maintenanceLifetime: '', | |
29 | businessModel: '', | |
be04c6fd | 30 | hardwareInformation: '' |
ccc00cb2 C |
31 | } |
32 | ||
ccc00cb2 | 33 | languages: string[] = [] |
4402b54d | 34 | categories: string[] = [] |
36f9424f | 35 | |
ba430d75 C |
36 | serverConfig: ServerConfig |
37 | ||
12c8a463 C |
38 | initialized = false |
39 | ||
64e0f8cf C |
40 | private lastScrollHash: string |
41 | ||
36f9424f | 42 | constructor ( |
45e0d669 | 43 | private viewportScroller: ViewportScroller, |
b42f9c40 | 44 | private route: ActivatedRoute, |
f3081d64 | 45 | private notifier: Notifier, |
b42f9c40 | 46 | private instanceService: InstanceService |
36f9424f C |
47 | ) {} |
48 | ||
49 | get instanceName () { | |
ba430d75 | 50 | return this.serverConfig.instance.name |
36f9424f C |
51 | } |
52 | ||
d3e56c0c | 53 | get isContactFormEnabled () { |
ba430d75 | 54 | return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled |
d3e56c0c C |
55 | } |
56 | ||
c8000975 | 57 | get isNSFW () { |
ba430d75 | 58 | return this.serverConfig.instance.isNSFW |
c8000975 C |
59 | } |
60 | ||
b42f9c40 | 61 | async ngOnInit () { |
12c8a463 | 62 | const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData |
ba430d75 | 63 | |
12c8a463 | 64 | this.serverConfig = serverConfig |
b42f9c40 C |
65 | |
66 | this.languages = languages | |
67 | this.categories = categories | |
68 | ||
69 | this.shortDescription = about.instance.shortDescription | |
70 | ||
b42f9c40 | 71 | this.html = await this.instanceService.buildHtml(about) |
12c8a463 C |
72 | |
73 | this.initialized = true | |
36f9424f C |
74 | } |
75 | ||
45e0d669 | 76 | ngAfterViewChecked () { |
12c8a463 | 77 | if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) { |
64e0f8cf C |
78 | this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', '')) |
79 | ||
80 | this.lastScrollHash = window.location.hash | |
81 | } | |
45e0d669 RK |
82 | } |
83 | ||
d3e56c0c C |
84 | openContactModal () { |
85 | return this.contactAdminModal.show() | |
86 | } | |
f3081d64 K |
87 | |
88 | onClickCopyLink (anchor: HTMLAnchorElement) { | |
89 | const link = anchor.href | |
90 | copyToClipboard(link) | |
91 | this.notifier.success(link, $localize `Link copied`) | |
92 | } | |
36f9424f | 93 | } |