diff --git a/src/common/__tests__/hotbar-store.test.ts b/src/common/__tests__/hotbar-store.test.ts index ff94248713..805ad6a711 100644 --- a/src/common/__tests__/hotbar-store.test.ts +++ b/src/common/__tests__/hotbar-store.test.ts @@ -24,6 +24,8 @@ describe("HotbarStore", () => { describe("add", () => { it("adds a hotbar", () => { + const hotbarStore = HotbarStore.getInstanceOrCreate(); + hotbarStore.add({ name: "hottest" }); expect(hotbarStore.hotbars.length).toEqual(2); }); diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index 62e967baf3..478279d9c0 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -116,6 +116,7 @@ export class HotbarStore extends BaseStore { } switchToPrevious() { + const hotbarStore = HotbarStore.getInstance(); let index = hotbarStore.activeHotbarIndex - 1; if (index < 0) { @@ -126,6 +127,7 @@ export class HotbarStore extends BaseStore { } switchToNext() { + const hotbarStore = HotbarStore.getInstance(); let index = hotbarStore.activeHotbarIndex + 1; if (index >= hotbarStore.hotbars.length) { diff --git a/src/renderer/components/hotbar/hotbar-add-command.tsx b/src/renderer/components/hotbar/hotbar-add-command.tsx index b4cd57c626..5ec5734219 100644 --- a/src/renderer/components/hotbar/hotbar-add-command.tsx +++ b/src/renderer/components/hotbar/hotbar-add-command.tsx @@ -1,13 +1,13 @@ import React from "react"; import { observer } from "mobx-react"; -import { hotbarStore } from "../../../common/hotbar-store"; +import { HotbarStore } from "../../../common/hotbar-store"; import { CommandOverlay } from "../command-palette"; import { Input, InputValidator } from "../input"; const uniqueHotbarName: InputValidator = { condition: ({ required }) => required, message: () => "Hotbar with this name already exists", - validate: value => !hotbarStore.getByName(value), + validate: value => !HotbarStore.getInstance().getByName(value), }; @observer @@ -18,6 +18,8 @@ export class HotbarAddCommand extends React.Component { return; } + const hotbarStore = HotbarStore.getInstance(); + const hotbar = hotbarStore.add({ name }); diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index 3108f21d37..197671b034 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -30,11 +30,11 @@ export class HotbarMenu extends React.Component { } previous() { - hotbarStore.switchToPrevious(); + HotbarStore.getInstance().switchToPrevious(); } next() { - hotbarStore.switchToNext(); + HotbarStore.getInstance().switchToNext(); } openSelector() { @@ -43,7 +43,7 @@ export class HotbarMenu extends React.Component { render() { const { className } = this.props; - const hotbarIndex = hotbarStore.activeHotbarIndex + 1; + const hotbarIndex = HotbarStore.getInstance().activeHotbarIndex + 1; return (
diff --git a/src/renderer/components/hotbar/hotbar-remove-command.tsx b/src/renderer/components/hotbar/hotbar-remove-command.tsx index ccd9e1d45d..185ff65497 100644 --- a/src/renderer/components/hotbar/hotbar-remove-command.tsx +++ b/src/renderer/components/hotbar/hotbar-remove-command.tsx @@ -2,19 +2,20 @@ import React from "react"; import { observer } from "mobx-react"; import { Select } from "../select"; import { computed } from "mobx"; -import { hotbarStore } from "../../../common/hotbar-store"; +import { HotbarStore } from "../../../common/hotbar-store"; import { CommandOverlay } from "../command-palette"; import { ConfirmDialog } from "../confirm-dialog"; @observer export class HotbarRemoveCommand extends React.Component { @computed get options() { - return hotbarStore.hotbars.map((hotbar) => { + return HotbarStore.getInstance().hotbars.map((hotbar) => { return { value: hotbar.id, label: hotbar.name }; }); } onChange(id: string): void { + const hotbarStore = HotbarStore.getInstance(); const hotbar = hotbarStore.getById(id); if (!hotbar) { diff --git a/src/renderer/components/hotbar/hotbar-switch-command.tsx b/src/renderer/components/hotbar/hotbar-switch-command.tsx index 2e6aa705ed..991c5927ca 100644 --- a/src/renderer/components/hotbar/hotbar-switch-command.tsx +++ b/src/renderer/components/hotbar/hotbar-switch-command.tsx @@ -2,7 +2,7 @@ import React from "react"; import { observer } from "mobx-react"; import { Select } from "../select"; import { computed } from "mobx"; -import { hotbarStore } from "../../../common/hotbar-store"; +import { HotbarStore } from "../../../common/hotbar-store"; import { CommandOverlay } from "../command-palette"; import { HotbarAddCommand } from "./hotbar-add-command"; import { HotbarRemoveCommand } from "./hotbar-remove-command"; @@ -13,6 +13,7 @@ export class HotbarSwitchCommand extends React.Component { private static removeActionId = "__remove__"; @computed get options() { + const hotbarStore = HotbarStore.getInstance(); const options = hotbarStore.hotbars.map((hotbar) => { return { value: hotbar.id, label: hotbar.name }; }); @@ -37,7 +38,7 @@ export class HotbarSwitchCommand extends React.Component { return; default: - hotbarStore.activeHotbarId = idOrAction; + HotbarStore.getInstance().activeHotbarId = idOrAction; CommandOverlay.close(); } }