build: Use prettier for typescript
Stop ignoring .ts files in prettier and fix existing issues.
This commit is contained in:
@@ -8,9 +8,8 @@ describe('ThemeToggleComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ThemeToggleComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [ThemeToggleComponent]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ThemeToggleComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
@@ -8,18 +8,19 @@ import { SettingsService } from 'app/settings/settings.service';
|
||||
styleUrls: ['./theme-toggle.component.scss']
|
||||
})
|
||||
export class ThemeToggleComponent implements OnInit, OnChanges {
|
||||
|
||||
darkModeOn: boolean;
|
||||
|
||||
constructor(private themingService: ThemingService,
|
||||
private settingsService: SettingsService) { }
|
||||
constructor(
|
||||
private themingService: ThemingService,
|
||||
private settingsService: SettingsService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.darkModeOn = (this.settingsService.themeDarkEnabled === 'true');
|
||||
this.darkModeOn = this.settingsService.themeDarkEnabled === 'true';
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
this.darkModeOn = (this.settingsService.themeDarkEnabled === 'true');
|
||||
this.darkModeOn = this.settingsService.themeDarkEnabled === 'true';
|
||||
}
|
||||
|
||||
toggleTheme() {
|
||||
@@ -27,5 +28,4 @@ export class ThemeToggleComponent implements OnInit, OnChanges {
|
||||
this.settingsService.setThemeDarkEnabled(this.darkModeOn ? 'true' : 'false');
|
||||
this.themingService.setDarkMode(this.darkModeOn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,20 +7,21 @@ import { BehaviorSubject } from 'rxjs';
|
||||
export class ThemingService {
|
||||
private darkModeOn = false;
|
||||
|
||||
themes = ['dark-theme', 'light-theme']; // <- list all themes in this array
|
||||
themes = [
|
||||
'dark-theme',
|
||||
'light-theme'
|
||||
]; // <- list all themes in this array
|
||||
theme = new BehaviorSubject('light-theme'); // <- initial theme
|
||||
|
||||
constructor(private ref: ApplicationRef) {
|
||||
// Initially check if dark mode is enabled on system
|
||||
this.darkModeOn =
|
||||
window.matchMedia &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
this.darkModeOn = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
|
||||
// If dark mode is enabled then directly switch to the dark-theme
|
||||
this.setDarkMode(this.darkModeOn);
|
||||
|
||||
// Watch for changes of the preference
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addListener(e => {
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addListener((e) => {
|
||||
const turnOn = e.matches;
|
||||
this.theme.next(turnOn ? 'dark-theme' : 'light-theme');
|
||||
|
||||
@@ -30,9 +31,7 @@ export class ThemingService {
|
||||
}
|
||||
|
||||
isDarkMode(): boolean {
|
||||
this.darkModeOn =
|
||||
window.matchMedia &&
|
||||
window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
this.darkModeOn = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
return this.darkModeOn;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user