]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-instance/about-instance.component.ts
Fix action dropdown height
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
CommitLineData
67ed6552 1import { ViewportScroller } from '@angular/common'
8ee25e17 2import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
67ed6552 3import { ActivatedRoute } from '@angular/router'
2989628b 4import { Notifier, ServerService } from '@app/core'
789ba349 5import { AboutHTML } from '@app/shared/shared-instance'
5c16e6bc 6import { copyToClipboard } from '@root-helpers/utils'
f6cf8e8d 7import { HTMLServerConfig, ServerStats } from '@shared/models/server'
b42f9c40 8import { ResolverData } from './about-instance.resolver'
5c16e6bc 9import { ContactAdminModalComponent } from './contact-admin-modal.component'
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 16export class AboutInstanceComponent implements OnInit, AfterViewChecked {
8ee25e17 17 @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
5c16e6bc 18 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
d3e56c0c 19
789ba349
C
20 aboutHTML: AboutHTML
21 descriptionElement: HTMLDivElement
ccc00cb2 22
ccc00cb2 23 languages: string[] = []
4402b54d 24 categories: string[] = []
789ba349 25 shortDescription = ''
36f9424f 26
12c8a463
C
27 initialized = false
28
f6cf8e8d
C
29 serverStats: ServerStats
30
2989628b
C
31 private serverConfig: HTMLServerConfig
32
64e0f8cf
C
33 private lastScrollHash: string
34
36f9424f 35 constructor (
45e0d669 36 private viewportScroller: ViewportScroller,
b42f9c40 37 private route: ActivatedRoute,
f3081d64 38 private notifier: Notifier,
789ba349 39 private serverService: ServerService
36f9424f
C
40 ) {}
41
42 get instanceName () {
ba430d75 43 return this.serverConfig.instance.name
36f9424f
C
44 }
45
d3e56c0c 46 get isContactFormEnabled () {
ba430d75 47 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
d3e56c0c
C
48 }
49
c8000975 50 get isNSFW () {
ba430d75 51 return this.serverConfig.instance.isNSFW
c8000975
C
52 }
53
789ba349 54 ngOnInit () {
f6cf8e8d
C
55 const { about, languages, categories, aboutHTML, descriptionElement, serverStats }: ResolverData = this.route.snapshot.data.instanceData
56
57 this.serverStats = serverStats
789ba349
C
58
59 this.aboutHTML = aboutHTML
60 this.descriptionElement = descriptionElement
61
62 this.languages = languages
63 this.categories = categories
64
65 this.shortDescription = about.instance.shortDescription
ba430d75 66
2989628b 67 this.serverConfig = this.serverService.getHTMLConfig()
b42f9c40 68
5c16e6bc
C
69 this.route.data.subscribe(data => {
70 if (!data?.isContact) return
71
72 const prefill = this.route.snapshot.queryParams
73
74 this.contactAdminModal.show(prefill)
75 })
76
12c8a463 77 this.initialized = true
36f9424f
C
78 }
79
45e0d669 80 ngAfterViewChecked () {
12c8a463 81 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
64e0f8cf
C
82 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
83
84 this.lastScrollHash = window.location.hash
85 }
45e0d669
RK
86 }
87
f3081d64
K
88 onClickCopyLink (anchor: HTMLAnchorElement) {
89 const link = anchor.href
90 copyToClipboard(link)
9df52d66 91 this.notifier.success(link, $localize`Link copied`)
f3081d64 92 }
36f9424f 93}