-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoggle-theme.component.ts
37 lines (31 loc) · 1.08 KB
/
toggle-theme.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Component } from '@angular/core';
import { Subject, debounceTime } from 'rxjs';
import { AuthService } from '@services/auth.service';
import { SettingService } from '@services/setting.service';
import { UserService } from '@services/user.service';
@Component({
selector: 'app-toggle-theme',
templateUrl: './toggle-theme.component.html',
styleUrls: ['./toggle-theme.component.css']
})
export class ToggleThemeComponent {
private themeChanged: Subject<boolean> = new Subject();
constructor(
private settingService: SettingService,
private userService: UserService,
private authService: AuthService,
) {
this.themeChanged.pipe(debounceTime(800))
.subscribe(checked => this.userService.setTheme(checked));
}
changeTheme(event: Event): void {
const checked = (event.target as HTMLInputElement)?.checked;
if(this.authService.isAuthenticated()) {
this.themeChanged.next(checked);
}
this.settingService.setTheme((checked) ? 'dark' : 'light' ); // set local
}
get isDarkMode(): boolean {
return this.settingService.isDarkMode();
}
}