|
|
@@ -25,28 +25,19 @@ import SupportAgentIcon from '@mui/icons-material/SupportAgent';
|
|
|
import Collapse from '@mui/material/Collapse';
|
|
|
import ExpandLess from '@mui/icons-material/ExpandLess';
|
|
|
import ExpandMore from '@mui/icons-material/ExpandMore';
|
|
|
-import { useNavigate } from 'react-router-dom'
|
|
|
-
|
|
|
-const SubMenuList = [5,6,7,8,9]
|
|
|
+import { useNavigate, useResolvedPath, useMatch } from 'react-router-dom'
|
|
|
|
|
|
function SubMenuItem (props) {
|
|
|
|
|
|
let navigate = useNavigate()
|
|
|
-
|
|
|
- function change (event){
|
|
|
- props.change(event, props.index)
|
|
|
- if(props.route){
|
|
|
- navigate(props.route)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let isOn = props.selected === props.index
|
|
|
+ let resolved = useResolvedPath(props.route);
|
|
|
+ let match = useMatch({ path: resolved.pathname, end: true });
|
|
|
|
|
|
return(
|
|
|
<ListItem
|
|
|
- sx={{ pl: 9}}
|
|
|
- selected={isOn}
|
|
|
- onClick={change}
|
|
|
+ sx={{ pl: 9, color : '#25344f'}}
|
|
|
+ selected={match}
|
|
|
+ onClick={() => navigate(props.route)}
|
|
|
button
|
|
|
>
|
|
|
<ListItemText
|
|
|
@@ -62,27 +53,21 @@ function SubMenuItem (props) {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-function Item (props) {
|
|
|
-
|
|
|
+function NavItem (props) {
|
|
|
+
|
|
|
let navigate = useNavigate()
|
|
|
-
|
|
|
- function change (event){
|
|
|
- console.log('change >>> ', props)
|
|
|
- props.change(event, props.index)
|
|
|
- navigate(props.route)
|
|
|
- }
|
|
|
-
|
|
|
- let isOn = props.selected === props.index
|
|
|
+ let resolved = useResolvedPath(props.route);
|
|
|
+ let match = useMatch({ path: resolved.pathname, end: true });
|
|
|
|
|
|
return(
|
|
|
<ListItem
|
|
|
sx={{ color : '#25344f'}}
|
|
|
- selected={isOn}
|
|
|
- onClick={change}
|
|
|
+ selected={match}
|
|
|
+ onClick={() => navigate(props.route) }
|
|
|
button
|
|
|
>
|
|
|
<ListItemIcon>
|
|
|
- {props.icon}
|
|
|
+ {props.icon && props.icon}
|
|
|
</ListItemIcon>
|
|
|
<ListItemText
|
|
|
sx={{
|
|
|
@@ -100,36 +85,9 @@ function Item (props) {
|
|
|
|
|
|
export const MainListItems = (props) => {
|
|
|
|
|
|
- const [selectedIndex, setSelectedIndex] = React.useState(0);
|
|
|
-
|
|
|
-
|
|
|
- const handleListItemClick = (event, index) => {
|
|
|
- setSelectedIndex(index);
|
|
|
- };
|
|
|
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
|
- React.useEffect( () => {
|
|
|
-
|
|
|
- if(!props.AppBarVisible ){
|
|
|
- return setOpen(false)
|
|
|
- }
|
|
|
-
|
|
|
- if( SubMenuList.includes(selectedIndex) && !open ){
|
|
|
- if(props.AppBarVisible){
|
|
|
- return setOpen(false)
|
|
|
- }else{
|
|
|
- return setOpen(true)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if( !SubMenuList.includes(selectedIndex) && !props.AppBarVisible ){
|
|
|
- return setOpen(false)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }, [props, selectedIndex, open])
|
|
|
-
|
|
|
const showPruebas = () => {
|
|
|
if(!props.AppBarVisible){
|
|
|
props.setAppBarVisible(true);
|
|
|
@@ -139,14 +97,17 @@ export const MainListItems = (props) => {
|
|
|
|
|
|
return(
|
|
|
<List>
|
|
|
+
|
|
|
<ListSubheader inset>MENÚ</ListSubheader>
|
|
|
- <Item icon={<HomeIcon/>} index={0} selected={selectedIndex} change={handleListItemClick} title="Inicio" route="home" />
|
|
|
- <Item icon={<WorkIcon/>} index={1} selected={selectedIndex} change={handleListItemClick} title="Puestos" route="puestos" />
|
|
|
- <Item icon={<VisibilityOffIcon/>} selected={selectedIndex} change={handleListItemClick} index={2} title="Contraseñas" route="contrasenas" />
|
|
|
- <Item icon={<PeopleAltIcon/>} selected={selectedIndex} change={handleListItemClick} index={3} title="Expedientes" route="expedientes" />
|
|
|
- <Item icon={<EqualizerIcon/>} selected={selectedIndex} change={handleListItemClick} index={4} title="Resultados" route="resultados" />
|
|
|
|
|
|
- <ListItem selected={ SubMenuList.includes(selectedIndex) } onClick={showPruebas}>
|
|
|
+ <NavItem icon={<HomeIcon/>} title="Inicio" route="home" />
|
|
|
+ <NavItem icon={<WorkIcon/>} title="Puestos" route="puestos" />
|
|
|
+ <NavItem icon={<VisibilityOffIcon/>} index={2} title="Contraseñas" route="contrasenas" />
|
|
|
+ <NavItem icon={<PeopleAltIcon/>} title="Expedientes" route="expedientes" />
|
|
|
+ <NavItem icon={<EqualizerIcon/>} title="Resultados" route="resultados" />
|
|
|
+
|
|
|
+ {/*<ListItem selected={false} onClick={showPruebas}>*/}
|
|
|
+ <ListItem onClick={showPruebas}>
|
|
|
<ListItemIcon>
|
|
|
<FingerprintIcon />
|
|
|
</ListItemIcon>
|
|
|
@@ -168,17 +129,17 @@ export const MainListItems = (props) => {
|
|
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
|
|
<List component="div" disablePadding>
|
|
|
|
|
|
- <SubMenuItem route="pruebas/crear" selected={selectedIndex} index={5} change={handleListItemClick} title="Crear Prueba" />
|
|
|
- <SubMenuItem route="pruebas/listar" change={handleListItemClick} selected={selectedIndex} index={6} title="Listado de pruebas" />
|
|
|
- <SubMenuItem route="pruebas/aplicar" selected={selectedIndex} index={7} change={handleListItemClick} title="Aplicar" />
|
|
|
- <SubMenuItem selected={selectedIndex} index={8} change={handleListItemClick} title="Respuestas" />
|
|
|
- <SubMenuItem selected={selectedIndex} index={9} change={handleListItemClick} title="Calificaciones" />
|
|
|
+ <NavItem route="pruebas/crear" title="Crear Prueba" />
|
|
|
+ <NavItem route="pruebas/listar" title="Listado de pruebas" />
|
|
|
+ <NavItem route="pruebas/aplicar" title="Aplicar" />
|
|
|
+ <NavItem route="pruebas/respuestas" title="Respuestas" />
|
|
|
+ <NavItem route="pruebas/calificaciones" title="Calificaciones" />
|
|
|
|
|
|
</List>
|
|
|
</Collapse>
|
|
|
|
|
|
- <Item icon={<MiscellaneousServicesIcon/>} selected={selectedIndex} change={handleListItemClick} index={10} title="Configuraciones" route="configuraciones" />
|
|
|
- <Item icon={<HistoryIcon/>} selected={selectedIndex} change={handleListItemClick} index={11} title="Historial" route="historial" />
|
|
|
+ <NavItem icon={<MiscellaneousServicesIcon/>} title="Configuraciones" route="configuraciones" />
|
|
|
+ <NavItem icon={<HistoryIcon/>} title="Historial" route="historial" />
|
|
|
</List>
|
|
|
)
|
|
|
};
|
|
|
@@ -186,8 +147,8 @@ export const MainListItems = (props) => {
|
|
|
export const secondaryListItems = (
|
|
|
<Nav>
|
|
|
<ListSubheader inset>EXTRAS</ListSubheader>
|
|
|
- <Item selected={false} icon={<StarIcon/>} title="Elementos" route="/work" />
|
|
|
- <Item selected={false} icon={<OndemandVideoIcon/>} title="Tutoriales" route="/work" />
|
|
|
- <Item selected={false} icon={<SupportAgentIcon/>} title="Asistencia Técnica" route="/work" />
|
|
|
+ <NavItem selected={false} icon={<StarIcon/>} title="Elementos" route="/work" />
|
|
|
+ <NavItem selected={false} icon={<OndemandVideoIcon/>} title="Tutoriales" route="/work" />
|
|
|
+ <NavItem selected={false} icon={<SupportAgentIcon/>} title="Asistencia Técnica" route="/work" />
|
|
|
</Nav>
|
|
|
);
|