mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-04 14:42:53 +00:00
Store theme preference in local storage
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
"@types/split.js": "^1.4.0",
|
"@types/split.js": "^1.4.0",
|
||||||
"copy-webpack-plugin": "^6.0.1",
|
"copy-webpack-plugin": "^6.0.1",
|
||||||
"html-webpack-plugin": "^4.3.0",
|
"html-webpack-plugin": "^4.3.0",
|
||||||
"minecraft-schemas": "^0.1.5",
|
"minecraft-schemas": "^0.1.6",
|
||||||
"split.js": "^1.5.11",
|
"split.js": "^1.5.11",
|
||||||
"ts-loader": "^7.0.4",
|
"ts-loader": "^7.0.4",
|
||||||
"typescript": "^3.9.3",
|
"typescript": "^3.9.3",
|
||||||
|
|||||||
+18
-5
@@ -13,6 +13,7 @@ import Split from 'split.js'
|
|||||||
|
|
||||||
import { SandboxSchema } from './Sandbox'
|
import { SandboxSchema } from './Sandbox'
|
||||||
|
|
||||||
|
const LOCAL_STORAGE_THEME = 'theme'
|
||||||
|
|
||||||
const modelFromPath = (p: string) => p.split('/').filter(e => e.length !== 0).pop() ?? ''
|
const modelFromPath = (p: string) => p.split('/').filter(e => e.length !== 0).pop() ?? ''
|
||||||
|
|
||||||
@@ -141,13 +142,25 @@ Promise.all([
|
|||||||
}, { capture: true, once: true })
|
}, { capture: true, once: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
themeSelector.addEventListener('click', evt => {
|
const updateTheme = (theme: string | null) => {
|
||||||
if (document.body.getAttribute('data-style') === 'dark') {
|
if (theme === null) return
|
||||||
document.body.setAttribute('data-style', 'light')
|
if (theme === 'dark') {
|
||||||
themeSelector.classList.remove('toggled')
|
|
||||||
} else {
|
|
||||||
document.body.setAttribute('data-style', 'dark')
|
document.body.setAttribute('data-style', 'dark')
|
||||||
themeSelector.classList.add('toggled')
|
themeSelector.classList.add('toggled')
|
||||||
|
localStorage.setItem(LOCAL_STORAGE_THEME, 'dark')
|
||||||
|
} else {
|
||||||
|
document.body.setAttribute('data-style', 'light')
|
||||||
|
themeSelector.classList.remove('toggled')
|
||||||
|
localStorage.setItem(LOCAL_STORAGE_THEME, 'light')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateTheme(localStorage.getItem(LOCAL_STORAGE_THEME))
|
||||||
|
|
||||||
|
themeSelector.addEventListener('click', evt => {
|
||||||
|
if (document.body.getAttribute('data-style') === 'dark') {
|
||||||
|
updateTheme('light')
|
||||||
|
} else {
|
||||||
|
updateTheme('dark')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user