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

92 lines
2.6 KiB
TypeScript

import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Subscription } from 'rxjs';
import { environment } from '../environments/environment';
import { Theme } from './core/enums/theme.enum';
import { LanguageService } from './core/services/language.service';
import { ThemeService } from './core/services/theme.service';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import { slideInAnimation } from './shared/animations/main';
import { FramaKeyboardShortcuts } from './shared/shortcuts/main';
import { ShortcutInput } from 'ng-keyboard-shortcuts';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
animations: [slideInAnimation],
})
export class AppComponent implements OnInit, OnDestroy, AfterViewInit {
shortcuts: ShortcutInput[] = FramaKeyboardShortcuts;
public appTitle: string = environment.appTitle;
public appLogo: string = environment.appLogo;
public themeClass: string;
public isSidebarOpened = false;
public devModeEnabled = !environment.production;
private themeSubscription: Subscription;
public environment = environment;
constructor(
private router: Router,
private titleService: Title,
private themeService: ThemeService,
private languageService: LanguageService // private mockingService: MockingService
) {}
ngOnInit(): void {
this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
window.scrollTo(0, 0);
});
if (!environment.production) {
this.appTitle += ' [DEV]';
}
this.titleService.setTitle(this.appTitle);
this.languageService.configureAndInitTranslations();
this.themeSubscription = this.themeService.theme.subscribe((theme: Theme) => {
switch (theme) {
case Theme.DARK:
this.themeClass = 'theme-dark-crystal';
break;
case Theme.CONTRAST:
this.themeClass = 'theme-hot-covid';
break;
case Theme.RED:
this.themeClass = 'theme-hot-covid';
break;
default:
this.themeClass = 'theme-light-watermelon';
}
});
}
ngAfterViewInit() {
this.shortcuts.push({
key: ['cmd + g'],
label: 'Help',
description: 'Command + G',
command: (e) => console.log(e),
preventDefault: true,
});
}
ngOnDestroy(): void {
if (this.themeSubscription) {
this.themeSubscription.unsubscribe();
}
}
public toggleSidebar(status: boolean): void {
this.isSidebarOpened = status === true;
}
prepareRoute(outlet: RouterOutlet) {
return outlet && outlet.activatedRouteData && outlet.activatedRouteData.animation;
}
}