]>
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' |
2989628b | 5 | import { Notifier, ServerService } from '@app/core' |
8ee25e17 | 6 | import { CustomMarkupService } from '@app/shared/shared-custom-markup' |
67ed6552 | 7 | import { InstanceService } from '@app/shared/shared-instance' |
2989628b | 8 | import { About, HTMLServerConfig, ServerConfig } from '@shared/models' |
8ee25e17 | 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> |
d3e56c0c | 19 | |
45c0fb35 | 20 | shortDescription = '' |
8ee25e17 | 21 | descriptionContent: string |
ccc00cb2 C |
22 | |
23 | html = { | |
ccc00cb2 C |
24 | terms: '', |
25 | codeOfConduct: '', | |
26 | moderationInformation: '', | |
be04c6fd | 27 | administrator: '', |
f45c7cc7 FC |
28 | creationReason: '', |
29 | maintenanceLifetime: '', | |
30 | businessModel: '', | |
be04c6fd | 31 | hardwareInformation: '' |
ccc00cb2 C |
32 | } |
33 | ||
ccc00cb2 | 34 | languages: string[] = [] |
4402b54d | 35 | categories: string[] = [] |
36f9424f | 36 | |
12c8a463 C |
37 | initialized = false |
38 | ||
2989628b C |
39 | private serverConfig: HTMLServerConfig |
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, |
2989628b | 47 | private serverService: ServerService, |
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 () { |
2989628b | 64 | const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData |
ba430d75 | 65 | |
2989628b | 66 | this.serverConfig = this.serverService.getHTMLConfig() |
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 | ||
f3081d64 K |
87 | onClickCopyLink (anchor: HTMLAnchorElement) { |
88 | const link = anchor.href | |
89 | copyToClipboard(link) | |
90 | this.notifier.success(link, $localize `Link copied`) | |
91 | } | |
36f9424f | 92 | } |