From 49d2fa11bd5767e2f1155f220758d4fafc22c7df Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sat, 4 Mar 2023 21:57:00 +0200 Subject: [PATCH] light dark toggle --- src/components/layout/LightDarkToggle.js | 25 +++++++++ src/components/layout/ProfileButton.js | 62 +++++++++++++++++++++ src/components/layout/TopBar.js | 68 +++--------------------- 3 files changed, 93 insertions(+), 62 deletions(-) create mode 100644 src/components/layout/LightDarkToggle.js create mode 100644 src/components/layout/ProfileButton.js diff --git a/src/components/layout/LightDarkToggle.js b/src/components/layout/LightDarkToggle.js new file mode 100644 index 0000000..cc42262 --- /dev/null +++ b/src/components/layout/LightDarkToggle.js @@ -0,0 +1,25 @@ +import React from "react"; +import { IconButton } from "@material-ui/core"; +import { + Brightness2 as MoonIcon, + WbSunny as SunIcon +} from "@material-ui/icons"; +import { useApplicationTheme } from "../../providers/ThemeProvider"; + +const LightDarkToggle = () => { + const { isDark, onDarkModeChanged } = useApplicationTheme(); + + const handleChange = () => onDarkModeChanged(!isDark); + + return ( + + {isDark ? : } + + ); +}; + +export default LightDarkToggle; diff --git a/src/components/layout/ProfileButton.js b/src/components/layout/ProfileButton.js new file mode 100644 index 0000000..fbf6784 --- /dev/null +++ b/src/components/layout/ProfileButton.js @@ -0,0 +1,62 @@ +import React, { useState } from "react"; +import { IconButton, Menu, MenuItem } from "@material-ui/core"; +import AccountCircle from "@material-ui/icons/AccountCircle"; +import { useHistory } from "react-router-dom"; +import { useTuitioClient } from "@flare/tuitio-client-react"; + +const ProfileButton = () => { + const history = useHistory(); + const { logout } = useTuitioClient(); + + const [anchorEl, setAnchorEl] = useState(null); + const openUserMenu = Boolean(anchorEl); + + const handleMenu = event => { + setAnchorEl(event.currentTarget); + }; + + const handleClose = () => { + setAnchorEl(null); + }; + + return ( +
+ + + + + { + history.push("/user-profile"); + handleClose(); + }} + > + Profile + + logout()}>Logout + +
+ ); +}; + +export default ProfileButton; diff --git a/src/components/layout/TopBar.js b/src/components/layout/TopBar.js index e115da4..026f3a4 100644 --- a/src/components/layout/TopBar.js +++ b/src/components/layout/TopBar.js @@ -1,39 +1,17 @@ -import React, { useState } from "react"; +import React from "react"; import PropTypes from "prop-types"; import clsx from "clsx"; import { makeStyles } from "@material-ui/core/styles"; -import { - AppBar, - Toolbar, - Typography, - IconButton, - Menu, - MenuItem -} from "@material-ui/core"; - +import { AppBar, Toolbar, Typography, IconButton } from "@material-ui/core"; import MenuIcon from "@material-ui/icons/Menu"; -import AccountCircle from "@material-ui/icons/AccountCircle"; -import { useHistory } from "react-router-dom"; -import { useTuitioClient } from "@flare/tuitio-client-react"; +import ProfileButton from "./ProfileButton"; +import LightDarkToggle from "./LightDarkToggle"; import styles from "./styles"; const useStyles = makeStyles(styles); const TopBar = ({ open, handleDrawerOpen }) => { const classes = useStyles(); - const history = useHistory(); - const { logout } = useTuitioClient(); - - const [userAnchorEl, setUserAnchorEl] = useState(null); - const openUserMenu = Boolean(userAnchorEl); - - const handleMenu = event => { - setUserAnchorEl(event.currentTarget); - }; - - const handleClose = () => { - setUserAnchorEl(null); - }; return ( { Network resurrector -
- - - - - { - history.push("/user-profile"); - handleClose(); - }} - > - Profile - - logout()}>Logout - -
+ +
);