Make sure that there are only ever 12 slots in a hotbar (#3379)

* Make sure that there are only ever 12 slots in a hotbar

- Send notification if hotbar is full

- Filter out on every fromStore call

- Switch to broadcast on error

- Fix addToHotbar index check

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* change when to/fromStore are located

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-08-04 10:37:08 +03:00
1 parent fb74859f66
commit 17b14f9871
6 files changed
+146 -27

No files matched your search

+12 -1
View File
@@ -21,13 +21,14 @@
import React from "react";
import { ipcRenderer, IpcRendererEvent } from "electron";
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ClusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs, ListNamespaceForbiddenArgs } from "../../common/ipc";
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, UpdateAvailableFromMain, BackchannelArg, ClusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs, ListNamespaceForbiddenArgs, HotbarTooManyItems } from "../../common/ipc";
import { Notifications, notificationsStore } from "../components/notifications";
import { Button } from "../components/button";
import { isMac } from "../../common/vars";
import { ClusterStore } from "../../common/cluster-store";
import { navigate } from "../navigation";
import { entitySettingsURL } from "../../common/routes";
import { defaultHotbarCells } from "../../common/hotbar-types";
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
notificationsStore.remove(notificationId);
@@ -112,6 +113,10 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
);
}
function HotbarTooManyItemsHandler(): void {
Notifications.error(`Cannot have more than ${defaultHotbarCells} items pinned to a hotbar`);
}
export function registerIpcHandlers() {
onCorrect({
source: ipcRenderer,
@@ -125,4 +130,10 @@ export function registerIpcHandlers() {
listener: ListNamespacesForbiddenHandler,
verifier: isListNamespaceForbiddenArgs,
});
onCorrect({
source: ipcRenderer,
channel: HotbarTooManyItems,
listener: HotbarTooManyItemsHandler,
verifier: (args: unknown[]): args is [] => args.length === 0,
});
}