PeerTube/client/src/app/+about/about-instance/about-instance.component.ts

101 lines
2.9 KiB
TypeScript
Raw Normal View History

2020-06-23 14:10:17 +02:00
import { ViewportScroller } from '@angular/common'
import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2020-06-23 14:10:17 +02:00
import { ActivatedRoute } from '@angular/router'
2021-06-04 13:31:41 +02:00
import { Notifier, ServerService } from '@app/core'
2020-06-23 14:10:17 +02:00
import { InstanceService } from '@app/shared/shared-instance'
import { copyToClipboard } from '@root-helpers/utils'
import { HTMLServerConfig } from '@shared/models/server'
2020-02-03 10:31:34 +01:00
import { ResolverData } from './about-instance.resolver'
import { ContactAdminModalComponent } from './contact-admin-modal.component'
2018-01-31 17:47:36 +01:00
@Component({
2018-06-27 14:21:03 +02:00
selector: 'my-about-instance',
templateUrl: './about-instance.component.html',
styleUrls: [ './about-instance.component.scss' ]
2018-01-31 17:47:36 +01:00
})
export class AboutInstanceComponent implements OnInit, AfterViewChecked {
@ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
@ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
2019-01-10 11:12:41 +01:00
2018-05-23 10:41:08 +02:00
shortDescription = ''
descriptionContent: string
2019-08-23 15:23:27 +02:00
html = {
terms: '',
codeOfConduct: '',
moderationInformation: '',
administrator: '',
creationReason: '',
maintenanceLifetime: '',
businessModel: '',
hardwareInformation: ''
2019-08-23 15:23:27 +02:00
}
languages: string[] = []
categories: string[] = []
2018-01-31 17:47:36 +01:00
2020-11-16 16:46:15 +01:00
initialized = false
2021-06-04 13:31:41 +02:00
private serverConfig: HTMLServerConfig
2020-06-16 09:56:24 +02:00
private lastScrollHash: string
2018-01-31 17:47:36 +01:00
constructor (
private viewportScroller: ViewportScroller,
2020-02-03 10:31:34 +01:00
private route: ActivatedRoute,
private notifier: Notifier,
2021-06-04 13:31:41 +02:00
private serverService: ServerService,
2020-02-03 10:31:34 +01:00
private instanceService: InstanceService
2018-01-31 17:47:36 +01:00
) {}
get instanceName () {
2019-12-18 15:31:54 +01:00
return this.serverConfig.instance.name
2018-01-31 17:47:36 +01:00
}
2019-01-10 11:12:41 +01:00
get isContactFormEnabled () {
2019-12-18 15:31:54 +01:00
return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
2019-01-10 11:12:41 +01:00
}
2019-02-21 15:44:12 +01:00
get isNSFW () {
2019-12-18 15:31:54 +01:00
return this.serverConfig.instance.isNSFW
2019-02-21 15:44:12 +01:00
}
2020-02-03 10:31:34 +01:00
async ngOnInit () {
2021-06-04 13:31:41 +02:00
const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
2019-12-18 15:31:54 +01:00
2021-06-04 13:31:41 +02:00
this.serverConfig = this.serverService.getHTMLConfig()
2020-02-03 10:31:34 +01:00
this.route.data.subscribe(data => {
if (!data?.isContact) return
const prefill = this.route.snapshot.queryParams
this.contactAdminModal.show(prefill)
})
2020-02-03 10:31:34 +01:00
this.languages = languages
this.categories = categories
this.shortDescription = about.instance.shortDescription
this.descriptionContent = about.instance.description
2020-02-03 10:31:34 +01:00
this.html = await this.instanceService.buildHtml(about)
2020-11-16 16:46:15 +01:00
this.initialized = true
2018-01-31 17:47:36 +01:00
}
ngAfterViewChecked () {
2020-11-16 16:46:15 +01:00
if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
2020-06-16 09:56:24 +02:00
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
this.lastScrollHash = window.location.hash
}
}
onClickCopyLink (anchor: HTMLAnchorElement) {
const link = anchor.href
copyToClipboard(link)
this.notifier.success(link, $localize `Link copied`)
}
2018-01-31 17:47:36 +01:00
}