From 239f377aefc971d9d67eb7baef4c513a1d91f6d4 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 7 Aug 2020 13:56:03 +1000 Subject: [PATCH] Changed map and token select number inputs to not prepend a 0 when typing numbers --- src/components/map/MapSettings.js | 4 ++-- src/components/token/TokenSettings.js | 2 +- src/modals/SelectMapModal.js | 10 +++++++++- src/modals/SelectTokensModal.js | 8 +++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/map/MapSettings.js b/src/components/map/MapSettings.js index 1f11809..e5526a7 100644 --- a/src/components/map/MapSettings.js +++ b/src/components/map/MapSettings.js @@ -64,7 +64,7 @@ function MapSettings({ onSettingsChange("gridX", parseInt(e.target.value)) } @@ -78,7 +78,7 @@ function MapSettings({ onSettingsChange("gridY", parseInt(e.target.value)) } diff --git a/src/components/token/TokenSettings.js b/src/components/token/TokenSettings.js index 92d2f20..e11b9e8 100644 --- a/src/components/token/TokenSettings.js +++ b/src/components/token/TokenSettings.js @@ -19,7 +19,7 @@ function TokenSettings({ onSettingsChange("defaultSize", parseInt(e.target.value)) } diff --git a/src/modals/SelectMapModal.js b/src/modals/SelectMapModal.js index 3737027..def4c2b 100644 --- a/src/modals/SelectMapModal.js +++ b/src/modals/SelectMapModal.js @@ -249,7 +249,15 @@ function SelectMapModal({ selectedMapId && (!isEmpty(mapSettingChanges) || !isEmpty(mapStateSettingChanges)) ) { - await updateMap(selectedMapId, mapSettingChanges); + // Ensure grid values are positive + let verifiedChanges = { ...mapSettingChanges }; + if ("gridX" in verifiedChanges) { + verifiedChanges.gridX = verifiedChanges.gridX || 1; + } + if ("gridY" in verifiedChanges) { + verifiedChanges.gridY = verifiedChanges.gridY || 1; + } + await updateMap(selectedMapId, verifiedChanges); await updateMapState(selectedMapId, mapStateSettingChanges); setMapSettingChanges({}); diff --git a/src/modals/SelectTokensModal.js b/src/modals/SelectTokensModal.js index d6b3f14..0feea1b 100644 --- a/src/modals/SelectTokensModal.js +++ b/src/modals/SelectTokensModal.js @@ -112,7 +112,13 @@ function SelectTokensModal({ isOpen, onRequestClose }) { async function applyTokenChanges() { if (selectedTokenId && !isEmpty(tokenSettingChanges)) { - await updateToken(selectedTokenId, tokenSettingChanges); + // Ensure size value is positive + let verifiedChanges = { ...tokenSettingChanges }; + if ("defaultSize" in verifiedChanges) { + verifiedChanges.defaultSize = verifiedChanges.defaultSize || 1; + } + + await updateToken(selectedTokenId, verifiedChanges); setTokenSettingChanges({}); } }