AltitudeWeb/frontend/src/app/theme/theme.component.ts

37 lines
907 B
TypeScript
Raw Normal View History

import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {ThemeService} from './theme.service';
import {THEME_MODE} from '../constant';
@Component({
standalone: false,
selector: 'app-theme',
templateUrl: './theme.component.html',
styleUrl: './theme.component.scss'
})
export class ThemeComponent implements OnInit, OnDestroy {
isDarkMode: boolean = false;
private themeSubscription: Subscription | null = null;
constructor(private themeService: ThemeService) {
}
ngOnInit(): void {
this.themeSubscription = this.themeService.theme$.subscribe(theme => {
this.isDarkMode = theme === THEME_MODE.DARK;
});
}
toggleTheme(): void {
this.isDarkMode = this.themeService.toggleTheme() === THEME_MODE.DARK;
}
ngOnDestroy(): void {
if (this.themeSubscription) {
this.themeSubscription.unsubscribe();
}
}
}