funky-framadate-front/src/app/app.component.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Component, Inject } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { NavigationStart, Router } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import { filter } from 'rxjs/operators';
import { ConfigService } from './services/config.service';
import { environment } from '../environments/environment';
@Component({
2020-04-21 10:50:26 +02:00
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
2020-04-21 10:50:26 +02:00
step: string;
isDevelopmentEnv = false;
2020-04-21 10:50:26 +02:00
constructor(
private translate: TranslateService,
public config: ConfigService,
@Inject(DOCUMENT) private document,
private route: Router
) {
this.detectCurrentTabOnRouteChange();
2020-04-21 10:50:26 +02:00
this.isDevelopmentEnv = !environment.production;
}
2020-04-21 10:50:26 +02:00
detectCurrentTabOnRouteChange() {
this.route.events.subscribe((event: any) => {});
this.route.events
.pipe(filter((event) => event instanceof NavigationStart))
.subscribe((event: NavigationStart) => {
this.scrollGoToTop();
this.updateCurrentTab(event);
// only if there is a poll ID
this.config.fetchPollFromRoute(event);
});
}
2019-10-01 15:43:37 +02:00
2020-04-21 10:50:26 +02:00
scrollGoToTop() {
this.document.documentElement.scrollTop = 0;
}
2020-01-23 14:23:07 +01:00
2020-04-21 10:50:26 +02:00
updateCurrentTab(event) {
if (event.url) {
const tab = event.url.split('/');
if (tab && tab[2]) {
this.step = tab[2];
} else {
this.step = 'home';
}
}
}
}