Skip to content

Commit

Permalink
persist the last theme chosen by the user
Browse files Browse the repository at this point in the history
  • Loading branch information
jandsonrj committed Aug 2, 2023
1 parent 9525d69 commit 3620dcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ function Header({ darkMode, setDarkMode }) {
}

const handleToggleDarkMode = () => {
setDarkMode(prevMode => !prevMode)
setDarkMode(prevMode => {
const newMode = !prevMode
localStorage.setItem('darkMode', newMode ? '1' : '0')
return newMode
})
}

return (
Expand Down
5 changes: 5 additions & 0 deletions frontend/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default function MyApp(props) {
if (jssStyles) {
jssStyles.parentElement.removeChild(jssStyles)
}

const darkModePreference = localStorage.getItem('darkMode')
if (darkModePreference) {
setDarkMode(darkModePreference === '1')
}
}, [])

const light = createTheme({
Expand Down

0 comments on commit 3620dcc

Please sign in to comment.