Fix about scrolling behaviour
This commit is contained in:
parent
a75eb7489c
commit
12c8a46362
|
@ -35,12 +35,13 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
|
||||||
|
|
||||||
serverConfig: ServerConfig
|
serverConfig: ServerConfig
|
||||||
|
|
||||||
|
initialized = false
|
||||||
|
|
||||||
private lastScrollHash: string
|
private lastScrollHash: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private viewportScroller: ViewportScroller,
|
private viewportScroller: ViewportScroller,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private serverService: ServerService,
|
|
||||||
private instanceService: InstanceService
|
private instanceService: InstanceService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -57,11 +58,9 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit () {
|
async ngOnInit () {
|
||||||
this.serverConfig = this.serverService.getTmpConfig()
|
const { about, languages, categories, serverConfig }: ResolverData = this.route.snapshot.data.instanceData
|
||||||
this.serverService.getConfig()
|
|
||||||
.subscribe(config => this.serverConfig = config)
|
|
||||||
|
|
||||||
const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
|
this.serverConfig = serverConfig
|
||||||
|
|
||||||
this.languages = languages
|
this.languages = languages
|
||||||
this.categories = categories
|
this.categories = categories
|
||||||
|
@ -73,10 +72,12 @@ export class AboutInstanceComponent implements OnInit, AfterViewChecked {
|
||||||
this.businessModel = about.instance.businessModel
|
this.businessModel = about.instance.businessModel
|
||||||
|
|
||||||
this.html = await this.instanceService.buildHtml(about)
|
this.html = await this.instanceService.buildHtml(about)
|
||||||
|
|
||||||
|
this.initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewChecked () {
|
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.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
|
||||||
|
|
||||||
this.lastScrollHash = window.location.hash
|
this.lastScrollHash = window.location.hash
|
||||||
|
|
|
@ -2,15 +2,19 @@ import { forkJoin } from 'rxjs'
|
||||||
import { map, switchMap } from 'rxjs/operators'
|
import { map, switchMap } from 'rxjs/operators'
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
|
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'
|
||||||
|
import { ServerService } from '@app/core'
|
||||||
import { InstanceService } from '@app/shared/shared-instance'
|
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()
|
@Injectable()
|
||||||
export class AboutInstanceResolver implements Resolve<any> {
|
export class AboutInstanceResolver implements Resolve<any> {
|
||||||
|
|
||||||
constructor (private instanceService: InstanceService) {}
|
constructor (
|
||||||
|
private instanceService: InstanceService,
|
||||||
|
private serverService: ServerService
|
||||||
|
) {}
|
||||||
|
|
||||||
resolve (route: ActivatedRouteSnapshot) {
|
resolve (route: ActivatedRouteSnapshot) {
|
||||||
return this.instanceService.getAbout()
|
return this.instanceService.getAbout()
|
||||||
|
@ -18,8 +22,9 @@ export class AboutInstanceResolver implements Resolve<any> {
|
||||||
switchMap(about => {
|
switchMap(about => {
|
||||||
return forkJoin([
|
return forkJoin([
|
||||||
this.instanceService.buildTranslatedLanguages(about),
|
this.instanceService.buildTranslatedLanguages(about),
|
||||||
this.instanceService.buildTranslatedCategories(about)
|
this.instanceService.buildTranslatedCategories(about),
|
||||||
]).pipe(map(([ languages, categories ]) => ({ about, languages, categories })))
|
this.serverService.getConfig()
|
||||||
|
]).pipe(map(([ languages, categories, serverConfig ]) => ({ about, languages, categories, serverConfig })))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue