diff --git a/src/common/__tests__/hotbar-store.test.ts b/src/common/__tests__/hotbar-store.test.ts index 1e3264f6fe..e029835006 100644 --- a/src/common/__tests__/hotbar-store.test.ts +++ b/src/common/__tests__/hotbar-store.test.ts @@ -330,8 +330,8 @@ describe("HotbarStore", () => { hotbarStore.addToHotbar(testCluster); - expect(hotbarStore.entityPinnedToHotbar(testCluster)).toBeTruthy(); - expect(hotbarStore.entityPinnedToHotbar(awsCluster)).toBeFalsy(); + expect(hotbarStore.isAddedToActive(testCluster)).toBeTruthy(); + expect(hotbarStore.isAddedToActive(awsCluster)).toBeFalsy(); }); }); diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index 07f6b7c841..f7b7de642d 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -171,7 +171,7 @@ export class HotbarStore extends BaseStore { }}; - if (this.entityPinnedToHotbar(item)) { + if (this.isAddedToActive(item)) { return; } @@ -279,7 +279,7 @@ export class HotbarStore extends BaseStore { * Checks if entity already pinned to hotbar * @returns boolean */ - entityPinnedToHotbar(entity: CatalogEntity) { + isAddedToActive(entity: CatalogEntity) { return !!this.getActive().items.find(item => item?.entity.uid === entity.metadata.uid); } } diff --git a/src/renderer/components/+catalog/catalog-entity-drawer-menu.tsx b/src/renderer/components/+catalog/catalog-entity-drawer-menu.tsx index fb6a0c934a..46225b4075 100644 --- a/src/renderer/components/+catalog/catalog-entity-drawer-menu.tsx +++ b/src/renderer/components/+catalog/catalog-entity-drawer-menu.tsx @@ -74,6 +74,10 @@ export class CatalogEntityDrawerMenu extends React.Comp HotbarStore.getInstance().addToHotbar(entity); } + removeFromHotbar(item: CatalogEntity): void { + HotbarStore.getInstance().removeFromHotbar(item.getId()); + } + getMenuItems(entity: T): React.ReactChild[] { if (!entity) { return []; @@ -98,11 +102,19 @@ export class CatalogEntityDrawerMenu extends React.Comp ); } - items.push( - this.addToHotbar(entity) }> - - - ); + if (!HotbarStore.getInstance().isAddedToActive(entity)) { + items.push( + this.addToHotbar(entity) }> + + + ); + } else { + items.push( + this.removeFromHotbar(entity)}> + + + ); + } return items; } diff --git a/src/renderer/components/+catalog/catalog.module.css b/src/renderer/components/+catalog/catalog.module.css index fa2c4438d3..fd730ae1e7 100644 --- a/src/renderer/components/+catalog/catalog.module.css +++ b/src/renderer/components/+catalog/catalog.module.css @@ -44,10 +44,6 @@ &:hover .pinIcon { opacity: 1; - - &:global(.disabled) { - opacity: 0.3; - } } } diff --git a/src/renderer/components/+catalog/catalog.tsx b/src/renderer/components/+catalog/catalog.tsx index 8c3d935b02..671fee082e 100644 --- a/src/renderer/components/+catalog/catalog.tsx +++ b/src/renderer/components/+catalog/catalog.tsx @@ -37,7 +37,7 @@ import { CatalogAddButton } from "./catalog-add-button"; import type { RouteComponentProps } from "react-router"; import { Notifications } from "../notifications"; import { MainLayout } from "../layout/main-layout"; -import { createAppStorage, cssNames } from "../../utils"; +import { createAppStorage, cssNames, prevDefault } from "../../utils"; import { makeCss } from "../../../common/utils/makeCss"; import { CatalogEntityDetails } from "./catalog-entity-details"; import { browseCatalogTab, catalogURL, CatalogViewRouteParam } from "../../../common/routes"; @@ -130,6 +130,10 @@ export class Catalog extends React.Component { HotbarStore.getInstance().addToHotbar(item.entity); } + removeFromHotbar(item: CatalogEntityItem): void { + HotbarStore.getInstance().removeFromHotbar(item.getId()); + } + onDetails = (item: CatalogEntityItem) => { if (this.catalogEntityStore.selectedItemId) { this.catalogEntityStore.selectedItemId = null; @@ -177,6 +181,8 @@ export class Catalog extends React.Component { } renderItemMenu = (item: CatalogEntityItem) => { + const isItemInHotbar = HotbarStore.getInstance().isAddedToActive(item.entity); + const onOpen = () => { this.contextMenu.menuItems = []; @@ -195,29 +201,32 @@ export class Catalog extends React.Component { )) } - this.addToHotbar(item)}> - Pin to Hotbar - + {!isItemInHotbar ? ( + this.addToHotbar(item)}> + Add to Hotbar + + ) : ( + this.removeFromHotbar(item)}> + Remove from Hotbar + + )} ); }; renderName(item: CatalogEntityItem) { - const disabledIcon = HotbarStore.getInstance().entityPinnedToHotbar(item.entity); + const isItemInHotbar = HotbarStore.getInstance().isAddedToActive(item.entity); return (
{item.name} { - event.stopPropagation(); - this.addToHotbar(item); - }}/> + tooltip={isItemInHotbar ? "Remove from Hotbar" : "Add to Hotbar"} + onClick={prevDefault(() => isItemInHotbar ? this.removeFromHotbar(item) : this.addToHotbar(item))} + />
); } diff --git a/src/renderer/components/hotbar/hotbar-entity-icon.tsx b/src/renderer/components/hotbar/hotbar-entity-icon.tsx index fc6628f3eb..651eee3881 100644 --- a/src/renderer/components/hotbar/hotbar-entity-icon.tsx +++ b/src/renderer/components/hotbar/hotbar-entity-icon.tsx @@ -30,7 +30,6 @@ import { navigate } from "../../navigation"; import { cssNames, IClassName } from "../../utils"; import { Icon } from "../icon"; import { HotbarIcon } from "./hotbar-icon"; -import { HotbarStore } from "../../../common/hotbar-store"; interface Props extends DOMAttributes { entity: CatalogEntity; @@ -87,10 +86,6 @@ export class HotbarEntityIcon extends React.Component { return catalogEntityRegistry.activeEntity?.metadata?.uid == item.getId(); } - isPersisted(entity: CatalogEntity) { - return HotbarStore.getInstance().getActive().items.find((item) => item?.entity?.uid === entity.metadata.uid) !== undefined; - } - render() { if (!this.contextMenu) { return null; @@ -106,21 +101,13 @@ export class HotbarEntityIcon extends React.Component { 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) - }); - } + menuItems.unshift({ + title: "Remove from Hotbar", + onClick: () => remove(entity.metadata.uid) + }); this.contextMenu.menuItems = menuItems; diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index 9055279437..571b978a79 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -138,7 +138,7 @@ export class HotbarMenu extends React.Component { tooltip={`${item.entity.name} (${item.entity.source})`} menuItems={[ { - title: "Unpin from Hotbar", + title: "Remove from Hotbar", onClick: () => this.removeItem(item.entity.uid) } ]}