Fix about scrolling behaviour

This commit is contained in:
Chocobozzz 2020-11-16 16:46:15 +01:00
parent a75eb7489c
commit 12c8a46362
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 17 additions and 11 deletions

View File

@ -35,12 +35,13 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
serverConfig: ServerConfig
initialized = false
private lastScrollHash: string
constructor (
private viewportScroller: ViewportScroller,
private route: ActivatedRoute,
private serverService: ServerService,
private instanceService: InstanceService
) {}
@ -57,11 +58,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
@ -73,10 +72,12 @@ 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 && window.location.hash !== this.lastScrollHash) {
if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
this.lastScrollHash = window.location.hash

View File

@ -2,15 +2,19 @@ import { forkJoin } from 'rxjs'
import { map, switchMap } from 'rxjs/operators'
import { Injectable } from '@angular/core'
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
import { ServerService } from '@app/core'
import { InstanceService } from '@app/shared/shared-instance'
import { About } from '@shared/models/server'
import { About, ServerConfig } from '@shared/models/server'
export type ResolverData = { about: About, languages: string[], categories: string[] }
export type ResolverData = { about: About, languages: string[], categories: string[], serverConfig: ServerConfig }
@Injectable()
export class AboutInstanceResolver implements Resolve<any> {
constructor (private instanceService: InstanceService) {}
constructor (
private instanceService: InstanceService,
private serverService: ServerService
) {}
resolve (route: ActivatedRouteSnapshot) {
return this.instanceService.getAbout()
@ -18,8 +22,9 @@ export class AboutInstanceResolver implements Resolve<any> {
switchMap(about => {
return forkJoin([
this.instanceService.buildTranslatedLanguages(about),
this.instanceService.buildTranslatedCategories(about)
]).pipe(map(([ languages, categories ]) => ({ about, languages, categories })))
this.instanceService.buildTranslatedCategories(about),
this.serverService.getConfig()
]).pipe(map(([ languages, categories, serverConfig ]) => ({ about, languages, categories, serverConfig })))
})
)
}