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

116 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-03-27 14:00:40 +01:00
import { NgFor, NgIf, ViewportScroller } from '@angular/common'
import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2024-03-04 10:01:52 +01:00
import { ActivatedRoute, RouterLink } from '@angular/router'
2021-06-04 13:31:41 +02:00
import { Notifier, ServerService } from '@app/core'
2024-03-27 14:00:40 +01:00
import { AboutHTML } from '@app/shared/shared-main/instance/instance.service'
import { maxBy } from '@peertube/peertube-core-utils'
import { HTMLServerConfig, ServerStats } from '@peertube/peertube-models'
import { copyToClipboard } from '@root-helpers/utils'
2024-03-27 14:00:40 +01:00
import { CustomMarkupContainerComponent } from '../../shared/shared-custom-markup/custom-markup-container.component'
import { InstanceFeaturesTableComponent } from '../../shared/shared-instance/instance-features-table.component'
import { PluginSelectorDirective } from '../../shared/shared-main/plugins/plugin-selector.directive'
2020-02-03 10:31:34 +01:00
import { ResolverData } from './about-instance.resolver'
import { ContactAdminModalComponent } from './contact-admin-modal.component'
2024-03-04 10:01:52 +01:00
import { InstanceStatisticsComponent } from './instance-statistics.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',
2024-03-04 10:01:52 +01:00
styleUrls: [ './about-instance.component.scss' ],
standalone: true,
imports: [
NgIf,
RouterLink,
NgFor,
CustomMarkupContainerComponent,
PluginSelectorDirective,
InstanceFeaturesTableComponent,
InstanceStatisticsComponent,
ContactAdminModalComponent
]
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
2023-01-19 14:52:27 +01:00
aboutHTML: AboutHTML
descriptionElement: HTMLDivElement
2019-08-23 15:23:27 +02:00
instanceBannerUrl: string
2019-08-23 15:23:27 +02:00
languages: string[] = []
categories: string[] = []
2023-01-19 14:52:27 +01:00
shortDescription = ''
2018-01-31 17:47:36 +01:00
2020-11-16 16:46:15 +01:00
initialized = false
2023-02-15 15:53:40 +01:00
serverStats: ServerStats
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,
2023-01-19 14:52:27 +01:00
private serverService: ServerService
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
}
2023-01-19 14:52:27 +01:00
ngOnInit () {
2023-02-15 15:53:40 +01:00
const { about, languages, categories, aboutHTML, descriptionElement, serverStats }: ResolverData = this.route.snapshot.data.instanceData
this.serverStats = serverStats
2023-01-19 14:52:27 +01:00
this.aboutHTML = aboutHTML
this.descriptionElement = descriptionElement
this.languages = languages
this.categories = categories
this.shortDescription = about.instance.shortDescription
2019-12-18 15:31:54 +01:00
this.instanceBannerUrl = about.instance.banners.length !== 0
2024-03-27 14:00:40 +01:00
? maxBy(about.instance.banners, 'width').path
: undefined
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-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)
2021-08-17 14:42:53 +02:00
this.notifier.success(link, $localize`Link copied`)
}
2018-01-31 17:47:36 +01:00
}