Skip to content

Commit

Permalink
fixed the fucking night mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamJoker committed Sep 13, 2019
1 parent 93ebc71 commit eed5c47
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/components/SwipeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,25 @@ const SwipeMenu = () => {
useEffect(() => {
if (themeSelectValue === "Dark") {
setIsNight(true);
localStorage.setItem("selectedTheme", "Dark");
// also set in local
} else {
setIsNight(false);
localStorage.setItem("selectedTheme", "Default");
}
}, [themeSelectValue]);

useEffect(() => {
if (isNight) {
//if the is night is true we will make the theme night else default
setThemeSelectValue("Dark");
const changeTheme = theme => {
setThemeSelectValue(theme);
localStorage.setItem("selectedTheme", theme);
};

const handleThemeToggle = () => {
if (!isNight) {
changeTheme("Dark");
setIsNight(false);
} else {
setThemeSelectValue("Default");
changeTheme("Default");
setIsNight(true);
}
}, [isNight, setThemeSelectValue]);
};

return (
<SwipeableDrawer
Expand All @@ -89,7 +92,7 @@ const SwipeMenu = () => {
exit={{ scale: 0 }}
// transition={{ duration: 0.5 }}
src={isNight ? sun : moon}
onClick={() => setIsNight(!isNight)}
onClick={() => handleThemeToggle()}
className="dayNightToggleBtn"
alt="sun moon icon"
/>
Expand Down

0 comments on commit eed5c47

Please sign in to comment.