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