From a730e174551037eddf4d412a8daf62387aced042 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Wed, 30 Sep 2020 13:00:13 +0200 Subject: [PATCH] feat: Store Theme in localStorage. Signed-off-by: Jorropo --- web/src/store/ThemeStore.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/src/store/ThemeStore.js b/web/src/store/ThemeStore.js index 55394241..8a3b9579 100644 --- a/web/src/store/ThemeStore.js +++ b/web/src/store/ThemeStore.js @@ -13,7 +13,10 @@ const detectBrowserTheme = () => { export const ThemeStore = ({ children }) => { const [theme, setTheme] = useState(themes.dark) - const changeTheme = (newName) => setTheme(themes[newName] || themes.dark) + const changeTheme = (newName) => { + window.localStorage.setItem("theme", newName) + setTheme(themes[newName] || themes.dark) + } const themeStyles = useMemo(() => { const primaryButtonColors = { @@ -42,6 +45,11 @@ export const ThemeStore = ({ children }) => { }, [theme]) useEffect(() => { + const lTheme = window.localStorage.getItem("theme") + if (lTheme) { + changeTheme(lTheme) + return + } const { isLight } = detectBrowserTheme() if (isLight) changeTheme('light') }, [])