Fix scrolling with hash in url

pull/2879/head
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
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 () {

View 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
}
}
}

View 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) {

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))
scrollEvent.subscribe(e => {
console.log(e)
if (e.position) {
return this.viewportScroller.scrollToPosition(e.position)
}