You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
frontend/src/app/app.component.ts

48 lines
1.5 KiB
TypeScript

import { Component, ElementRef, Renderer2 } from '@angular/core';
import { ColorThemeService } from './services/colorTheme.service';
4 years ago
import { AuthService } from './services/auth.service';
import { Router } from '@angular/router';
4 years ago
import { ViewChild } from '@angular/core';
import { MatSidenav } from '@angular/material/sidenav';
import { NavService } from './components/menu-list-item/nav.service';
4 years ago
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
4 years ago
})
export class AppComponent {
4 years ago
title = 'fLotte-fRontend';
4 years ago
darkThemeIsActive: boolean = false;
4 years ago
loggedIn = false;
4 years ago
@ViewChild('sidenav') public sideNav:MatSidenav;
@ViewChild('appDrawer') appDrawer: ElementRef;
4 years ago
4 years ago
constructor(
private renderer: Renderer2,
4 years ago
private themeService: ColorThemeService,
private authService: AuthService,
private router: Router,
private navService: NavService
4 years ago
) {
this.renderer.addClass(document.body, 'mat-app-background'); //so the background color changes dependent on current theme
this.themeService.load();
4 years ago
this.darkThemeIsActive = this.themeService.currentActive() === 'dark-theme';
4 years ago
this.authService.loggedIn.subscribe((value) => (this.loggedIn = value));
4 years ago
}
changeTheme(event) {
this.themeService.update(event.checked ? 'dark-theme' : 'light-theme');
4 years ago
}
logout() {
this.authService.logout().subscribe().add(() => this.router.navigate(['login']));
4 years ago
this.sideNav.close();
}
ngAfterViewInit() {
this.navService.appDrawer = this.appDrawer;
}
4 years ago
}