]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+about/about-instance/about-instance.component.ts
refactor scoped token service
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
index e1809d7b7f57cc63ba18e1a9a266e238a4f052dd..92ecd5263455e9066a0ac48be0dafaa783d6942e 100644 (file)
@@ -1,11 +1,12 @@
-import { Component, OnInit, ViewChild, AfterViewChecked } from '@angular/core'
-import { Notifier, ServerService } from '@app/core'
+import { ViewportScroller } from '@angular/common'
+import { AfterViewChecked, Component, OnInit, ViewChild } from '@angular/core'
+import { ActivatedRoute } from '@angular/router'
 import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component'
-import { InstanceService } from '@app/shared/instance/instance.service'
+import { Notifier } from '@app/core'
+import { copyToClipboard } from '../../../root-helpers/utils'
+import { InstanceService } from '@app/shared/shared-instance'
 import { ServerConfig } from '@shared/models'
-import { ActivatedRoute } from '@angular/router'
 import { ResolverData } from './about-instance.resolver'
-import { ViewportScroller } from '@angular/common'
 
 @Component({
   selector: 'my-about-instance',
@@ -35,10 +36,14 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
 
   serverConfig: ServerConfig
 
+  initialized = false
+
+  private lastScrollHash: string
+
   constructor (
     private viewportScroller: ViewportScroller,
     private route: ActivatedRoute,
-    private serverService: ServerService,
+    private notifier: Notifier,
     private instanceService: InstanceService
   ) {}
 
@@ -55,11 +60,9 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
   }
 
   async ngOnInit () {
-    this.serverConfig = this.serverService.getTmpConfig()
-    this.serverService.getConfig()
-        .subscribe(config => this.serverConfig = config)
+    const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData
 
-    const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
+    this.serverConfig = serverConfig
 
     this.languages = languages
     this.categories = categories
@@ -71,13 +74,25 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
     this.businessModel = about.instance.businessModel
 
     this.html = await this.instanceService.buildHtml(about)
+
+    this.initialized = true
   }
 
   ngAfterViewChecked () {
-    if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+    if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
+      this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+
+      this.lastScrollHash = window.location.hash
+    }
   }
 
   openContactModal () {
     return this.contactAdminModal.show()
   }
+
+  onClickCopyLink (anchor: HTMLAnchorElement) {
+    const link = anchor.href
+    copyToClipboard(link)
+    this.notifier.success(link, $localize `Link copied`)
+  }
 }