feat: close #22
This commit is contained in:
parent
ea01dc435e
commit
cd0103a255
1 changed files with 14 additions and 2 deletions
|
@ -22,13 +22,20 @@ function getStoredThemeSetting(): Theme {
|
|||
!storedTheme ||
|
||||
(storedTheme != Theme.Dark && storedTheme != Theme.Light)
|
||||
) {
|
||||
localStorage.setItem(themeKey, Theme.Dark)
|
||||
setTheme(Theme.Dark)
|
||||
return Theme.Dark
|
||||
}
|
||||
|
||||
return storedTheme
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets theme setting without applying them
|
||||
*/
|
||||
function setTheme(targetTheme: Theme) {
|
||||
localStorage.setItem(themeKey, targetTheme)
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies tailwind theme using classes based on current theme setting
|
||||
*/
|
||||
|
@ -43,10 +50,15 @@ function applyTheme() {
|
|||
export const useTheme = create<ThemeState>()((set) => {
|
||||
applyTheme()
|
||||
|
||||
addEventListener("storage", () => {
|
||||
setTheme(getStoredThemeSetting())
|
||||
applyTheme()
|
||||
})
|
||||
|
||||
return {
|
||||
theme: getStoredThemeSetting(),
|
||||
setTheme: (themeSetting: Theme) => {
|
||||
localStorage.setItem(themeKey, themeSetting)
|
||||
setTheme(themeSetting)
|
||||
applyTheme()
|
||||
set((state) => ({
|
||||
...state,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue