Fix scrolling with hash in url

This commit is contained in:
Chocobozzz 2020-06-16 09:56:24 +02:00
parent c7763eddd1
commit 64e0f8cf12
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 22 additions and 3 deletions

View File

@ -35,6 +35,8 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
serverConfig: ServerConfig serverConfig: ServerConfig
private lastScrollHash: string
constructor ( constructor (
private viewportScroller: ViewportScroller, private viewportScroller: ViewportScroller,
private route: ActivatedRoute, private route: ActivatedRoute,
@ -74,7 +76,11 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
} }
ngAfterViewChecked () { 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 () { openContactModal () {

View File

@ -8,11 +8,17 @@ import { ViewportScroller } from '@angular/common'
}) })
export class AboutPeertubeComponent implements AfterViewChecked { export class AboutPeertubeComponent implements AfterViewChecked {
private lastScrollHash: string
constructor ( constructor (
private viewportScroller: ViewportScroller private viewportScroller: ViewportScroller
) {} ) {}
ngAfterViewChecked () { 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
}
} }
} }

View File

@ -23,6 +23,8 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
userVideoQuotaUsedDaily = 0 userVideoQuotaUsedDaily = 0
userVideoQuotaDailyPercentage = 15 userVideoQuotaDailyPercentage = 15
private lastScrollHash: string
constructor ( constructor (
private viewportScroller: ViewportScroller, private viewportScroller: ViewportScroller,
private userService: UserService, private userService: UserService,
@ -64,7 +66,11 @@ export class MyAccountSettingsComponent implements OnInit, AfterViewChecked {
} }
ngAfterViewChecked () { 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) { onAvatarChange (formData: FormData) {

View File

@ -123,6 +123,7 @@ export class AppComponent implements OnInit, AfterViewInit {
const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll)) const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))
scrollEvent.subscribe(e => { scrollEvent.subscribe(e => {
console.log(e)
if (e.position) { if (e.position) {
return this.viewportScroller.scrollToPosition(e.position) return this.viewportScroller.scrollToPosition(e.position)
} }