From 8805ca469eb95850dffe5c852c8d6ca1a9db3f67 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 7 May 2023 01:58:36 +0300 Subject: [PATCH] Updated menu component to permanently display the selected item. --- private/Notes.txt | 1 - src/components/layout/Sidebar.js | 157 +++++++++++++++++++------------ 2 files changed, 96 insertions(+), 62 deletions(-) diff --git a/private/Notes.txt b/private/Notes.txt index d470bf8..88f4a96 100644 --- a/private/Notes.txt +++ b/private/Notes.txt @@ -6,7 +6,6 @@ Theming: https://v4.mui.com/customization/palette/ (Dark theme) Add in settings: -- reset cache - ping interval - notifications - test notification mechanism diff --git a/src/components/layout/Sidebar.js b/src/components/layout/Sidebar.js index 635fe17..038eba2 100644 --- a/src/components/layout/Sidebar.js +++ b/src/components/layout/Sidebar.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import PropTypes from "prop-types"; import clsx from "clsx"; import { makeStyles, useTheme } from "@material-ui/core/styles"; @@ -25,12 +25,83 @@ import styles from "./styles"; const useStyles = makeStyles(styles); +const menu = [ + { + order: 0, + items: [ + { + code: "dashboard", + name: "Menu.Dashboard", + route: "/dashboard", + icon: , + order: 0 + }, + { + code: "machines", + name: "Menu.Machines", + route: "/machines", + icon: , + order: 1 + }, + { + code: "system", + name: "Menu.System", + route: "/system", + icon: , + order: 2 + } + ] + }, + { + order: 1, + items: [ + { + code: "administration", + name: "Menu.Administration", + route: "/administration", + icon: , + order: 0 + }, + { + code: "settings", + name: "Menu.Settings", + route: "/settings", + icon: , + order: 1 + } + ] + }, + { + order: 2, + items: [ + { + code: "about", + name: "Menu.About", + route: "/about", + icon: , + order: 0 + } + ] + } +]; + +const sortedMenu = menu.sort((i1, i2) => i1 - i2); + const Sidebar = ({ open, handleDrawerClose }) => { + const [selected, setSelected] = useState(null); + const classes = useStyles(); const theme = useTheme(); const history = useHistory(); const { t } = useTranslation(); + const handleClick = route => () => { + setSelected(route); + history.push(route); + }; + + const isSelected = key => selected === key; + return ( { - - history.push("/dashboard")} - > - - - - - - history.push("/machines")} - > - - - - - - history.push("/system")}> - - - - - - - - - history.push("/administration")} - > - - - - - - history.push("/settings")} - > - - - - - - - - - history.push("/about")}> - - - - - - + + {sortedMenu.map((menu, index) => { + const isLast = index === sortedMenu.length - 1; + return ( + + + {menu.items + .sort((i1, i2) => i1 - i2) + .map(item => ( + + {item.icon} + + + ))} + + {!isLast && } + + ); + })} ); };