File tree Expand file tree Collapse file tree
Sidebar/MenuList/NavCollapse Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { Link } from 'react-router-dom' ;
2+ import { useDispatch , useSelector } from 'react-redux' ;
23
34// material-ui
45import { ButtonBase } from '@mui/material' ;
56
67// project imports
78import config from 'config' ;
89import Logo from 'ui-component/Logo' ;
10+ import { MENU_OPEN } from 'store/actions' ;
911
1012// ==============================|| MAIN LOGO ||============================== //
1113
12- const LogoSection = ( ) => (
13- < ButtonBase disableRipple component = { Link } to = { config . defaultPath } >
14- < Logo />
15- </ ButtonBase >
16- ) ;
14+ const LogoSection = ( ) => {
15+ const defaultId = useSelector ( ( state ) => state . customization . defaultId ) ;
16+ const dispatch = useDispatch ( ) ;
17+ return (
18+ < ButtonBase disableRipple onClick = { ( ) => dispatch ( { type : MENU_OPEN , id : defaultId } ) } component = { Link } to = { config . defaultPath } >
19+ < Logo />
20+ </ ButtonBase >
21+ ) ;
22+ } ;
1723
1824export default LogoSection ;
Original file line number Diff line number Diff line change 11import PropTypes from 'prop-types' ;
2- import { useState } from 'react' ;
2+ import { useEffect , useState } from 'react' ;
33import { useSelector } from 'react-redux' ;
4+ import { useLocation } from 'react-router' ;
45
56// material-ui
67import { useTheme } from '@mui/material/styles' ;
@@ -27,6 +28,35 @@ const NavCollapse = ({ menu, level }) => {
2728 setSelected ( ! selected ? menu . id : null ) ;
2829 } ;
2930
31+ const { pathname } = useLocation ( ) ;
32+ const checkOpenForParent = ( child , id ) => {
33+ child . forEach ( ( item ) => {
34+ if ( item . url === pathname ) {
35+ setOpen ( true ) ;
36+ setSelected ( id ) ;
37+ }
38+ } ) ;
39+ } ;
40+
41+ // menu collapse for sub-levels
42+ useEffect ( ( ) => {
43+ setOpen ( false ) ;
44+ setSelected ( null ) ;
45+ if ( menu . children ) {
46+ menu . children . forEach ( ( item ) => {
47+ if ( item . children ?. length ) {
48+ checkOpenForParent ( item . children , menu . id ) ;
49+ }
50+ if ( item . url === pathname ) {
51+ setSelected ( menu . id ) ;
52+ setOpen ( true ) ;
53+ }
54+ } ) ;
55+ }
56+
57+ // eslint-disable-next-line react-hooks/exhaustive-deps
58+ } , [ pathname , menu . children ] ) ;
59+
3060 // menu collapse & item
3161 const menus = menu . children ?. map ( ( item ) => {
3262 switch ( item . type ) {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import * as actionTypes from './actions';
66
77export const initialState = {
88 isOpen : [ ] , // for active default menu
9+ defaultId : 'default' ,
910 fontFamily : config . fontFamily ,
1011 borderRadius : config . borderRadius ,
1112 opened : true
You can’t perform that action at this time.
0 commit comments