feat: added dark mode functionality

This commit is contained in:
Peter Carl Pardo committed 2024-12-17 01:24:15 +08:00
1 parent 0e8b82be97
commit 663f2334d1
3 files changed
+17 -23

No files matched your search

+10 -6
View File
@@ -2,16 +2,20 @@ import React, { useEffect, useState } from "react";
import { IconButton } from "@mui/material";
import SunAndMoonIcon from "./SunAndMoonIcon";
import "./index.css";
import { useDispatch, useSelector } from "react-redux";
import { setMode } from "../../Features/UI/uiSlice";
const ThemeSwitch = () => {
// TODO: change to use the MUI theme
const [currentTheme, setCurrentTheme] = useState("light");
const toggleTheme = () =>
setCurrentTheme((prevState) => (prevState === "light" ? "dark" : "light"));
const mode = useSelector((state) => state.ui.mode);
const dispatch = useDispatch();
const toggleTheme = () => {
dispatch(setMode(mode === "light" ? "dark" : "light"));
};
useEffect(() => {
document.body.setAttribute("data-theme", currentTheme);
}, [currentTheme]);
document.body.setAttribute("data-theme", mode);
}, [mode]);
return (
<IconButton