Skip to content

Commit

Permalink
Add theme change button in ProfilePopover
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jun 21, 2024
1 parent e12392e commit af65529
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions frontend/src/components/popovers/ProfilePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@ import LogoutIcon from "@mui/icons-material/Logout";
import { useDispatch } from "react-redux";
import { setAccessToken } from "../../store/authSlice";
import { setUserData } from "../../store/userSlice";
import DarkModeIcon from "@mui/icons-material/DarkMode";
import LightModeIcon from "@mui/icons-material/LightMode";
import { useCurrentTheme } from "../../hooks/useCurrentTheme";
import { setTheme } from "../../store/configSlice";

function ProfilePopover(props: PopoverProps) {
const dispatch = useDispatch();
const themeMode = useCurrentTheme();

const handleLogout = () => {
dispatch(setAccessToken(null));
dispatch(setUserData(null));
};

const handleChangeTheme = () => {
dispatch(setTheme(themeMode == "light" ? "dark" : "light"));
};

return (
<Popover
anchorOrigin={{
Expand All @@ -32,6 +41,12 @@ function ProfilePopover(props: PopoverProps) {
{...props}
>
<MenuList>
<MenuItem onClick={handleChangeTheme}>
<ListItemIcon>
{themeMode === "light" ? <LightModeIcon /> : <DarkModeIcon />}
</ListItemIcon>
<ListItemText>Appearance</ListItemText>
</MenuItem>
<MenuItem onClick={handleLogout}>
<ListItemIcon>
<LogoutIcon fontSize="small" />
Expand Down

0 comments on commit af65529

Please sign in to comment.