-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
darkmode now functional + refactoring
- Loading branch information
Showing
12 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# led_control_app | ||
android app for https://github.com/leoratte/led_control | ||
web and android app for https://github.com/leoratte/led_control |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/app/components/darkmode-toggle/darkmode-toggle.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<ion-toggle (ionChange)="this.update($event.detail.checked)" [(checked)]="this.darkmode" slot="end"></ion-toggle> |
Empty file.
24 changes: 24 additions & 0 deletions
24
src/app/components/darkmode-toggle/darkmode-toggle.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { IonicModule } from '@ionic/angular'; | ||
|
||
import { DarkmodeToggleComponent } from './darkmode-toggle.component'; | ||
|
||
describe('DarkmodeToggleComponent', () => { | ||
let component: DarkmodeToggleComponent; | ||
let fixture: ComponentFixture<DarkmodeToggleComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ DarkmodeToggleComponent ], | ||
imports: [IonicModule.forRoot()] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DarkmodeToggleComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
src/app/components/darkmode-toggle/darkmode-toggle.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { StorageService } from 'src/app/services/storage.service'; | ||
|
||
const DARKMODE_KEY = 'darkmode'; | ||
@Component({ | ||
selector: 'app-darkmode-toggle', | ||
templateUrl: './darkmode-toggle.component.html', | ||
styleUrls: ['./darkmode-toggle.component.scss'], | ||
}) | ||
export class DarkmodeToggleComponent implements OnInit { | ||
public darkmode: boolean; | ||
constructor( | ||
private storageService: StorageService | ||
) { | ||
this.load(); | ||
} | ||
|
||
ngOnInit() {} | ||
|
||
load(): void { | ||
this.storageService | ||
.load(DARKMODE_KEY) | ||
.then((darkmode: boolean) =>{ | ||
if(darkmode != null) { | ||
this.darkmode = darkmode; | ||
} else { | ||
this.darkmode = window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
} | ||
this.apply(); | ||
}); | ||
} | ||
|
||
storeDarkmode(): void { | ||
this.storageService.store(DARKMODE_KEY, this.darkmode); | ||
} | ||
|
||
update(darkmode: boolean): void { | ||
this.darkmode = darkmode; | ||
this.storeDarkmode(); | ||
this.apply(); | ||
} | ||
|
||
apply(): void { | ||
if(this.darkmode){ | ||
document.body.setAttribute('data-theme', 'dark'); | ||
} | ||
else{ | ||
document.body.setAttribute('data-theme', 'light'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters