Persist the selected theme in the local storage
This commit is contained in:
parent
a983cd8322
commit
93f26c2d59
2 changed files with 17 additions and 2 deletions
|
@ -4,10 +4,10 @@ import React from 'react'
|
|||
import ReactDOM from 'react-dom'
|
||||
|
||||
import App from './app'
|
||||
import {setTheme, lightTheme} from './theme'
|
||||
import {loadTheme} from './theme'
|
||||
|
||||
import './styles/main.scss'
|
||||
import './styles/colors.scss'
|
||||
|
||||
setTheme(lightTheme)
|
||||
loadTheme()
|
||||
ReactDOM.render(<App/>, document.getElementById('octo-tasks-app'))
|
||||
|
|
|
@ -44,4 +44,19 @@ export function setTheme(theme: Theme): void {
|
|||
document.documentElement.style.setProperty('--button-fg', theme.buttonFg)
|
||||
document.documentElement.style.setProperty('--sidebar-bg', theme.sidebarBg)
|
||||
document.documentElement.style.setProperty('--sidebar-fg', theme.sidebarFg)
|
||||
localStorage.setItem('theme', JSON.stringify(theme))
|
||||
}
|
||||
|
||||
export function loadTheme(): void {
|
||||
const themeStr = localStorage.getItem('theme')
|
||||
if (themeStr) {
|
||||
try {
|
||||
const theme = JSON.parse(themeStr)
|
||||
setTheme(theme)
|
||||
} catch (e) {
|
||||
setTheme(lightTheme)
|
||||
}
|
||||
} else {
|
||||
setTheme(lightTheme)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue