remember theme in localStorage
This commit is contained in:
parent
e78980ebd1
commit
e3f7f600e8
|
@ -1,8 +1,10 @@
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
|
import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ThemeService {
|
export class ThemeService {
|
||||||
private theme = document.querySelector('body')
|
private theme = document.querySelector('body')
|
||||||
|
private darkTheme = false
|
||||||
private previousTheme = {}
|
private previousTheme = {}
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
|
@ -12,15 +14,24 @@ export class ThemeService {
|
||||||
this.previousTheme['submenuColor'] = 'rgb(32,32,32)'
|
this.previousTheme['submenuColor'] = 'rgb(32,32,32)'
|
||||||
this.previousTheme['inputColor'] = 'gray'
|
this.previousTheme['inputColor'] = 'gray'
|
||||||
this.previousTheme['inputPlaceholderColor'] = '#fff'
|
this.previousTheme['inputPlaceholderColor'] = '#fff'
|
||||||
|
|
||||||
|
this.darkTheme = (peertubeLocalStorage.getItem('theme') === 'dark')
|
||||||
|
console.log(this.darkTheme)
|
||||||
|
if (this.darkTheme) this.toggleDarkTheme(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleDarkTheme () {
|
toggleDarkTheme (setLocalStorage = true) {
|
||||||
// switch properties
|
// switch properties
|
||||||
this.switchProperty('mainBackgroundColor')
|
this.switchProperty('mainBackgroundColor')
|
||||||
this.switchProperty('mainForegroundColor')
|
this.switchProperty('mainForegroundColor')
|
||||||
this.switchProperty('submenuColor')
|
this.switchProperty('submenuColor')
|
||||||
this.switchProperty('inputColor')
|
this.switchProperty('inputColor')
|
||||||
this.switchProperty('inputPlaceholderColor')
|
this.switchProperty('inputPlaceholderColor')
|
||||||
|
|
||||||
|
if (setLocalStorage) {
|
||||||
|
this.darkTheme = !this.darkTheme
|
||||||
|
peertubeLocalStorage.setItem('theme', (this.darkTheme) ? 'dark' : 'default')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private switchProperty (property, newValue?) {
|
private switchProperty (property, newValue?) {
|
||||||
|
|
Loading…
Reference in New Issue