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

69 lines
1.8 KiB
TypeScript
Raw Normal View History

import {Component, Inject} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
2020-01-23 14:23:07 +01:00
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({
2019-09-27 16:10:03 +02:00
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
2020-01-21 12:04:14 +01:00
step: string;
isDevelopmentEnv=false;
2019-10-01 15:43:37 +02:00
constructor(private translate: TranslateService,
2020-04-02 16:36:09 +02:00
public config: ConfigService,
@Inject(DOCUMENT) private document,
private route: Router) {
this.detectCurrentTabOnRouteChange();
2020-04-11 16:16:25 +02:00
this.findLocalStoragePreferences();
this.isDevelopmentEnv = !environment.production
}
detectCurrentTabOnRouteChange() {
this.route.events.subscribe((event: any) => {
});
2020-04-02 16:36:09 +02:00
this.route.events.pipe(filter(event => event instanceof NavigationStart)).subscribe((event: NavigationStart) => {
2020-01-23 14:23:07 +01:00
this.scrollGoToTop();
this.updateCurrentTab(event);
// only if there is a poll ID
this.config.fetchPollFromRoute(event);
})
2019-10-01 15:43:37 +02:00
}
scrollGoToTop() {
this.document.documentElement.scrollTop = 0;
}
2020-01-23 14:23:07 +01:00
2020-04-02 16:36:09 +02:00
updateCurrentTab(event) {
2020-01-23 14:23:07 +01:00
if (event.url) {
const tab = event.url.split('/');
if (tab && tab[2]) {
this.step = tab[2];
} else {
this.step = 'home';
}
}
}
2020-04-11 16:16:25 +02:00
public findLocalStoragePreferences() {
const storage = window.localStorage;
if ( storage ){
const preferences = storage.getItem('FramadateConfig');
}
}
}