58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { 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 { UserRole } from './core/enums/user-role.enum';
|
|
import { MockingService } from './core/services/mocking.service';
|
|
import { ThemeService } from './core/services/theme.service';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.scss'],
|
|
})
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
public appTitle: string = environment.appTitle;
|
|
public themeClass: string;
|
|
public isSidebarOpened = false;
|
|
private themeSubscription: Subscription;
|
|
|
|
constructor(
|
|
private titleService: Title,
|
|
private themeService: ThemeService,
|
|
private mockingService: MockingService
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
if (!environment.production) {
|
|
this.appTitle += ' [DEV]';
|
|
this.mockingService.loadUser(UserRole.REGISTERED);
|
|
}
|
|
this.titleService.setTitle(this.appTitle);
|
|
this.themeSubscription = this.themeService.theme.subscribe((theme: Theme) => {
|
|
switch (theme) {
|
|
case Theme.DARK:
|
|
this.themeClass = 'theme-dark-crystal';
|
|
break;
|
|
case Theme.RED:
|
|
this.themeClass = 'theme-hot-covid';
|
|
break;
|
|
default:
|
|
this.themeClass = 'theme-light-watermelon';
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
if (this.themeSubscription) {
|
|
this.themeSubscription.unsubscribe();
|
|
}
|
|
}
|
|
|
|
public toggleSidebar(status: boolean): void {
|
|
this.isSidebarOpened = status === true;
|
|
}
|
|
}
|