Commit 560955bb authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix: better handling of scroll reset inside the app in case of navigation

parent 5ada347d
Pipeline #20297 passed with stages
in 3 minutes and 53 seconds
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { ProfileService } from './profile/services/profile.service';
import { AuthService } from './services/auth.service';
import { RouterListenerService } from './services/routerListener.service';
......@@ -10,7 +11,7 @@ import { WindowScrollService } from './shared/service/windowScroll.service';
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
export class AppComponent implements OnInit {
title = 'pamn';
constructor(
......@@ -18,7 +19,8 @@ export class AppComponent {
private authService: AuthService,
private profilService: ProfileService,
private windowScrollService: WindowScrollService,
private routerListener: RouterListenerService
private routerListener: RouterListenerService,
private router: Router
) {
if (this.authService.isLoggedIn()) {
this.profilService.getProfile();
......@@ -30,6 +32,18 @@ export class AppComponent {
this.routerListener.loadRouting();
}
ngOnInit(): void {
/**
* Reset scroll to top for article reading
*/
this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
document.getElementsByClassName('app-body')[0].scrollTo(0, 0);
});
}
private setHeightApp(): void {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
......
......@@ -21,7 +21,6 @@ export class PostDetailsComponent implements OnInit {
) {}
ngOnInit(): void {
this.resetScroll();
if (history.state.data) {
this.post = new Post(history.state.data);
this.post.safeHtml = this.sanitizer.bypassSecurityTrustHtml(this.post.html);
......@@ -37,14 +36,4 @@ export class PostDetailsComponent implements OnInit {
public backToPosts(): void {
this.routerListener.goToPreviousUrl();
}
/**
* Reset scroll to top for article reading
*/
private resetScroll(): void {
const classElement = document.getElementsByClassName('header-container');
if (classElement.length > 0) {
classElement[0].scrollIntoView();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment