]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
1 import { ViewportScroller } from '@angular/common'
2 import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
3 import { ActivatedRoute } from '@angular/router'
4 import { Notifier, ServerService } from '@app/core'
5 import { AboutHTML } from '@app/shared/shared-instance'
6 import { copyToClipboard } from '@root-helpers/utils'
7 import { HTMLServerConfig, ServerStats } from '@shared/models/server'
8 import { ResolverData } from './about-instance.resolver'
9 import { ContactAdminModalComponent } from './contact-admin-modal.component'
10
11 @Component({
12 selector: 'my-about-instance',
13 templateUrl: './about-instance.component.html',
14 styleUrls: [ './about-instance.component.scss' ]
15 })
16 export class AboutInstanceComponent implements OnInit, AfterViewChecked {
17 @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
18 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
19
20 aboutHTML: AboutHTML
21 descriptionElement: HTMLDivElement
22
23 languages: string[] = []
24 categories: string[] = []
25 shortDescription = ''
26
27 initialized = false
28
29 serverStats: ServerStats
30
31 private serverConfig: HTMLServerConfig
32
33 private lastScrollHash: string
34
35 constructor (
36 private viewportScroller: ViewportScroller,
37 private route: ActivatedRoute,
38 private notifier: Notifier,
39 private serverService: ServerService
40 ) {}
41
42 get instanceName () {
43 return this.serverConfig.instance.name
44 }
45
46 get isContactFormEnabled () {
47 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
48 }
49
50 get isNSFW () {
51 return this.serverConfig.instance.isNSFW
52 }
53
54 ngOnInit () {
55 const { about, languages, categories, aboutHTML, descriptionElement, serverStats }: ResolverData = this.route.snapshot.data.instanceData
56
57 this.serverStats = serverStats
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
66
67 this.serverConfig = this.serverService.getHTMLConfig()
68
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
77 this.initialized = true
78 }
79
80 ngAfterViewChecked () {
81 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
82 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
83
84 this.lastScrollHash = window.location.hash
85 }
86 }
87
88 onClickCopyLink (anchor: HTMLAnchorElement) {
89 const link = anchor.href
90 copyToClipboard(link)
91 this.notifier.success(link, $localize`Link copied`)
92 }
93 }