mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
calculate selected menu item on component moutn
This commit is contained in:
parent
3f7e8c1deb
commit
58612e8c1a
@ -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)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user