Skip to content

Commit

Permalink
Merge pull request #388 from berty/feat/rememberTheme
Browse files Browse the repository at this point in the history
feat: Store Theme in localStorage.
  • Loading branch information
Jorropo authored Sep 30, 2020
2 parents 036c8f9 + a730e17 commit 1bd68fc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion web/src/store/ThemeStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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')
}, [])
Expand Down

0 comments on commit 1bd68fc

Please sign in to comment.