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

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-10-17 11:12:53 +02:00
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Subscription } from 'rxjs';
2020-04-22 12:56:18 +02:00
2020-10-17 11:12:53 +02:00
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';
2021-04-25 11:58:58 +02:00
import { NavigationEnd, Router } from '@angular/router';
@Component({
2020-04-21 10:50:26 +02:00
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
2020-04-22 12:56:18 +02:00
export class AppComponent implements OnInit, OnDestroy {
public appTitle: string = environment.appTitle;
public appLogo: string = environment.appLogo;
2020-04-22 12:56:18 +02:00
public themeClass: string;
2020-05-01 19:10:17 +02:00
public isSidebarOpened = false;
public devModeEnabled = !environment.production;
2020-04-22 12:56:18 +02:00
private themeSubscription: Subscription;
2020-04-21 10:50:26 +02:00
constructor(
2021-04-25 11:58:58 +02:00
private router: Router,
2020-04-22 12:56:18 +02:00
private titleService: Title,
private themeService: ThemeService,
private languageService: LanguageService // private mockingService: MockingService
) {}
2020-04-22 12:56:18 +02:00
ngOnInit(): void {
2021-04-25 11:58:58 +02:00
this.router.events.subscribe((evt) => {
if (!(evt instanceof NavigationEnd)) {
return;
}
window.scrollTo(0, 0);
});
2020-04-22 12:56:18 +02:00
if (!environment.production) {
2020-05-01 19:10:17 +02:00
this.appTitle += ' [DEV]';
2020-04-22 12:56:18 +02:00
}
this.titleService.setTitle(this.appTitle);
2020-05-05 18:17:12 +02:00
this.languageService.configureAndInitTranslations();
2020-04-22 12:56:18 +02:00
this.themeSubscription = this.themeService.theme.subscribe((theme: Theme) => {
switch (theme) {
case Theme.DARK:
this.themeClass = 'theme-dark-crystal';
break;
2020-06-25 22:42:26 +02:00
case Theme.CONTRAST:
2020-04-22 12:56:18 +02:00
this.themeClass = 'theme-hot-covid';
break;
case Theme.RED:
this.themeClass = 'theme-hot-covid';
break;
2020-04-22 12:56:18 +02:00
default:
this.themeClass = 'theme-light-watermelon';
}
});
}
2020-04-22 12:56:18 +02:00
ngOnDestroy(): void {
if (this.themeSubscription) {
this.themeSubscription.unsubscribe();
}
2020-04-21 10:50:26 +02:00
}
2020-05-01 19:10:17 +02:00
public toggleSidebar(status: boolean): void {
this.isSidebarOpened = status === true;
2020-04-22 12:56:18 +02:00
}
}