From 12c8a46362f1f92d1c1a34991a76c55f625a80c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 Nov 2020 16:46:15 +0100 Subject: [PATCH] Fix about scrolling behaviour --- .../about-instance/about-instance.component.ts | 13 +++++++------ .../about-instance/about-instance.resolver.ts | 15 ++++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client/src/app/+about/about-instance/about-instance.component.ts b/client/src/app/+about/about-instance/about-instance.component.ts index c57ac69ab..bd587fa26 100644 --- a/client/src/app/+about/about-instance/about-instance.component.ts +++ b/client/src/app/+about/about-instance/about-instance.component.ts @@ -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 diff --git a/client/src/app/+about/about-instance/about-instance.resolver.ts b/client/src/app/+about/about-instance/about-instance.resolver.ts index b2349ba12..9a5924ebb 100644 --- a/client/src/app/+about/about-instance/about-instance.resolver.ts +++ b/client/src/app/+about/about-instance/about-instance.resolver.ts @@ -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 { - 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 { 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 }))) }) ) }