calculate selected menu item on component moutn

This commit is contained in:
SrGooglo 2024-09-13 15:07:09 +00:00
parent 3f7e8c1deb
commit 58612e8c1a

View File

@ -139,16 +139,13 @@ export default class Sidebar extends React.Component {
events = { events = {
"router.navigate": (path) => { "router.navigate": (path) => {
// recalculate sidebar selected item this.calculateSelectedMenuItem(path)
const item = [...this.state.topItems, ...this.state.bottomItems].find((item) => item.path === path) },
this.setState({
selectedMenuItem: item
})
}
} }
componentDidMount = async () => { componentDidMount = async () => {
this.calculateSelectedMenuItem(window.location.pathname)
for (const [event, handler] of Object.entries(this.events)) { for (const [event, handler] of Object.entries(this.events)) {
app.eventBus.on(event, handler) app.eventBus.on(event, handler)
} }
@ -170,6 +167,12 @@ export default class Sidebar extends React.Component {
delete app.layout.sidebar delete app.layout.sidebar
} }
calculateSelectedMenuItem = (path) => {
this.setState({
selectedMenuItem: [...this.state.topItems, ...this.state.bottomItems].find((item) => item.path === path)
})
}
addMenuItem = (group, item) => { addMenuItem = (group, item) => {
group = this.getMenuItemGroupStateKey(group) group = this.getMenuItemGroupStateKey(group)