/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import React from "react"; import { observer } from "mobx-react"; import { Input, InputValidator } from "../input"; import type { CreateHotbarData, CreateHotbarOptions } from "../../../common/hotbar-types"; import { withInjectables } from "@ogre-tools/injectable-react"; import commandOverlayInjectable from "../command-palette/command-overlay.injectable"; import hotbarManagerInjectable from "../../../common/hotbar-store.injectable"; import uniqueHotbarNameInjectable from "../input/validators/unique-hotbar-name.injectable"; interface Dependencies { closeCommandOverlay: () => void; addHotbar: (data: CreateHotbarData, { setActive }?: CreateHotbarOptions) => void; uniqueHotbarName: InputValidator; } const NonInjectedHotbarAddCommand = observer(({ closeCommandOverlay, addHotbar, uniqueHotbarName }: Dependencies) => { const onSubmit = (name: string) => { if (!name.trim()) { return; } addHotbar({ name }, { setActive: true }); closeCommandOverlay(); }; return ( <> Please provide a new hotbar name (Press "Enter" to confirm or "Escape" to cancel) ); }); export const HotbarAddCommand = withInjectables(NonInjectedHotbarAddCommand, { getProps: (di, props) => ({ closeCommandOverlay: di.inject(commandOverlayInjectable).close, addHotbar: di.inject(hotbarManagerInjectable).add, uniqueHotbarName: di.inject(uniqueHotbarNameInjectable), ...props, }), });