]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.component.ts
Fix about scrolling behaviour
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
1 import { ViewportScroller } from '@angular/common'
2 import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core'
3 import { ActivatedRoute } from '@angular/router'
4 import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component'
5 import { ServerService } from '@app/core'
6 import { InstanceService } from '@app/shared/shared-instance'
7 import { ServerConfig } from '@shared/models'
8 import { ResolverData } from './about-instance.resolver'
9
10 @Component({
11 selector: 'my-about-instance',
12 templateUrl: './about-instance.component.html',
13 styleUrls: [ './about-instance.component.scss' ]
14 })
15 export class AboutInstanceComponent implements OnInit, AfterViewChecked {
16 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
17
18 shortDescription = ''
19
20 html = {
21 description: '',
22 terms: '',
23 codeOfConduct: '',
24 moderationInformation: '',
25 administrator: '',
26 hardwareInformation: ''
27 }
28
29 creationReason = ''
30 maintenanceLifetime = ''
31 businessModel = ''
32
33 languages: string[] = []
34 categories: string[] = []
35
36 serverConfig: ServerConfig
37
38 initialized = false
39
40 private lastScrollHash: string
41
42 constructor (
43 private viewportScroller: ViewportScroller,
44 private route: ActivatedRoute,
45 private instanceService: InstanceService
46 ) {}
47
48 get instanceName () {
49 return this.serverConfig.instance.name
50 }
51
52 get isContactFormEnabled () {
53 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
54 }
55
56 get isNSFW () {
57 return this.serverConfig.instance.isNSFW
58 }
59
60 async ngOnInit () {
61 const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData
62
63 this.serverConfig = serverConfig
64
65 this.languages = languages
66 this.categories = categories
67
68 this.shortDescription = about.instance.shortDescription
69
70 this.creationReason = about.instance.creationReason
71 this.maintenanceLifetime = about.instance.maintenanceLifetime
72 this.businessModel = about.instance.businessModel
73
74 this.html = await this.instanceService.buildHtml(about)
75
76 this.initialized = true
77 }
78
79 ngAfterViewChecked () {
80 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
81 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
82
83 this.lastScrollHash = window.location.hash
84 }
85 }
86
87 openContactModal () {
88 return this.contactAdminModal.show()
89 }
90 }