Fix scrolling with hash in url
authorChocobozzz <me@florianbigard.com>
Tue, 16 Jun 2020 07:56:24 +0000 (09:56 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 16 Jun 2020 09:26:46 +0000 (11:26 +0200)
client/src/app/+about/about-instance/about-instance.component.ts
client/src/app/+about/about-peertube/about-peertube.component.ts
client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
client/src/app/app.component.ts

index e1809d7b7f57cc63ba18e1a9a266e238a4f052dd..15841be74e34339636530a11a6cc1cf038392506 100644 (file)
@@ -35,6 +35,8 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
 
   serverConfig: ServerConfig
 
+  private lastScrollHash: string
+
   constructor (
     private viewportScroller: ViewportScroller,
     private route: ActivatedRoute,
@@ -74,7 +76,11 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
   }
 
   ngAfterViewChecked () {
-    if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+    if (window.location.hash && window.location.hash !== this.lastScrollHash) {
+      this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+
+      this.lastScrollHash = window.location.hash
+    }
   }
 
   openContactModal () {
index 98c5f93c3f6c86fd9dfaf28a0b3d930897d34e55..b175a41bca37857547dc28887ad6a33e9be606c0 100644 (file)
@@ -8,11 +8,17 @@ import { ViewportScroller } from '@angular/common'
 })
 
 export class AboutPeertubeComponent implements AfterViewChecked {
+  private lastScrollHash: string
+
   constructor (
     private viewportScroller: ViewportScroller
   ) {}
 
   ngAfterViewChecked () {
-    if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+    if (window.location.hash && window.location.hash !== this.lastScrollHash) {
+      this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+
+      this.lastScrollHash = window.location.hash
+    }
   }
 }
index 5f2db985487dc873f0aff6fb824d6a909d708542..f73f3aa1e09de556fc9812d803dfe0c0df596f6d 100644 (file)
@@ -23,6 +23,8 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
   userVideoQuotaUsedDaily = 0
   userVideoQuotaDailyPercentage = 15
 
+  private lastScrollHash: string
+
   constructor (
     private viewportScroller: ViewportScroller,
     private userService: UserService,
@@ -64,7 +66,11 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
   }
 
   ngAfterViewChecked () {
-    if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+    if (window.location.hash && window.location.hash !== this.lastScrollHash) {
+      this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
+
+      this.lastScrollHash = window.location.hash
+    }
   }
 
   onAvatarChange (formData: FormData) {
index c77dc97deb2b78c685034a8ea16384dd7f262806..5541f555822d2fcf4ea495ac632959c42e48106b 100644 (file)
@@ -123,6 +123,7 @@ export class AppComponent implements OnInit, AfterViewInit {
     const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
 
     scrollEvent.subscribe(e => {
+      console.log(e)
       if (e.position) {
         return this.viewportScroller.scrollToPosition(e.position)
       }