diff --git a/src/renderer/components/+catalog/catalog.tsx b/src/renderer/components/+catalog/catalog.tsx index 77a7a7ccc4..929e19c27a 100644 --- a/src/renderer/components/+catalog/catalog.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -79,7 +79,7 @@ export class Catalog extends React.Component { async componentDidMount() { this.contextMenu = { - menuItems: [], + menuItems: observable.array([]), navigate: (url: string) => navigate(url) }; this.catalogEntityStore = new CatalogEntityStore(); @@ -169,8 +169,14 @@ export class Catalog extends React.Component { } renderItemMenu = (item: CatalogEntityItem) => { + const onOpen = () => { + this.contextMenu.menuItems = []; + + item.onContextMenuOpen(this.contextMenu); + }; + return ( - item.onContextMenuOpen(this.contextMenu)}> + { this.contextMenu.menuItems.map((menuItem, index) => ( this.onMenuItemClick(menuItem)}> diff --git a/src/renderer/components/hotbar/hotbar-entity-icon.tsx b/src/renderer/components/hotbar/hotbar-entity-icon.tsx index f1e22d2e79..aca3848502 100644 --- a/src/renderer/components/hotbar/hotbar-entity-icon.tsx +++ b/src/renderer/components/hotbar/hotbar-entity-icon.tsx @@ -23,7 +23,7 @@ import React, { DOMAttributes } from "react"; import { makeObservable, observable } from "mobx"; import { observer } from "mobx-react"; -import type { CatalogEntity, CatalogEntityContextMenuContext } from "../../../common/catalog"; +import type { CatalogEntity, CatalogEntityContextMenu, CatalogEntityContextMenuContext } from "../../../common/catalog"; import { catalogCategoryRegistry } from "../../api/catalog-category-registry"; import { catalogEntityRegistry } from "../../api/catalog-entity-registry"; import { navigate } from "../../navigation"; @@ -101,24 +101,28 @@ export class HotbarEntityIcon extends React.Component { active: this.isActive(entity), disabled: !entity }); + + const isPersisted = this.isPersisted(entity); const onOpen = async () => { + const menuItems: CatalogEntityContextMenu[] = []; + + if (!isPersisted) { + menuItems.unshift({ + title: "Pin to Hotbar", + onClick: () => add(entity, index) + }); + } else { + menuItems.unshift({ + title: "Unpin from Hotbar", + onClick: () => remove(entity.metadata.uid) + }); + } + + this.contextMenu.menuItems = menuItems; + await entity.onContextMenuOpen(this.contextMenu); }; const isActive = this.isActive(entity); - const isPersisted = this.isPersisted(entity); - const menuItems = this.contextMenu?.menuItems ?? []; - - if (!isPersisted) { - menuItems.unshift({ - title: "Pin to Hotbar", - onClick: () => add(entity, index) - }); - } else { - menuItems.unshift({ - title: "Unpin from Hotbar", - onClick: () => remove(entity.metadata.uid) - }); - } return ( { className={className} active={isActive} onMenuOpen={onOpen} - menuItems={menuItems} + menuItems={this.contextMenu.menuItems} {...elemProps} > { this.ledIcon }