From 44c0e964742ca9bd27ad5640c5a8267f1279544f Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 29 Jan 2023 23:36:21 -0800 Subject: [PATCH 1/3] Proper equality --- components/WeaponGrid/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/WeaponGrid/index.tsx b/components/WeaponGrid/index.tsx index 4dbdc346..c484ac41 100644 --- a/components/WeaponGrid/index.tsx +++ b/components/WeaponGrid/index.tsx @@ -164,7 +164,7 @@ const WeaponGrid = (props: Props) => { } function storeGridWeapon(gridWeapon: GridWeapon) { - if (gridWeapon.position == -1) { + if (gridWeapon.position === -1) { appState.grid.weapons.mainWeapon = gridWeapon appState.party.element = gridWeapon.object.element } else { From fa6b312f06cfbdcc3ed87246ba5d33ba23a05917 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 29 Jan 2023 23:36:37 -0800 Subject: [PATCH 2/3] Move storeGridWeapon to after conflict deletion Otherwise, we delete what we just stored --- components/WeaponGrid/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/WeaponGrid/index.tsx b/components/WeaponGrid/index.tsx index c484ac41..0fe9c291 100644 --- a/components/WeaponGrid/index.tsx +++ b/components/WeaponGrid/index.tsx @@ -183,9 +183,6 @@ const WeaponGrid = (props: Props) => { position: position, }) .then((response) => { - // Store new character in state - storeGridWeapon(response.data) - // Remove conflicting characters from state conflicts.forEach((c) => { if (appState.grid.weapons.mainWeapon?.object.id === c.id) { @@ -196,6 +193,9 @@ const WeaponGrid = (props: Props) => { } }) + // Store new character in state + storeGridWeapon(response.data.grid_weapon) + // Reset conflict resetConflict() From 05df606ea4d9c6ce8b4d6d9162db320fadf53196 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 29 Jan 2023 23:36:57 -0800 Subject: [PATCH 3/3] Don't POST if the user is adding the same weapon to a position --- components/WeaponGrid/index.tsx | 37 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/components/WeaponGrid/index.tsx b/components/WeaponGrid/index.tsx index 0fe9c291..f5dc668c 100644 --- a/components/WeaponGrid/index.tsx +++ b/components/WeaponGrid/index.tsx @@ -152,15 +152,34 @@ const WeaponGrid = (props: Props) => { if (weapon.uncap.ulb) uncapLevel = 5 else if (weapon.uncap.flb) uncapLevel = 4 - return await api.endpoints.weapons.create({ - weapon: { - party_id: partyId, - weapon_id: weapon.id, - position: position, - mainhand: position == -1, - uncap_level: uncapLevel, - }, - }) + let post = false + if ( + position === -1 && + (!appState.grid.weapons.mainWeapon || + (appState.grid.weapons.mainWeapon && + appState.grid.weapons.mainWeapon.object.id !== weapon.id)) + ) { + post = true + } else if ( + position !== -1 && + (!appState.grid.weapons.allWeapons[position] || + (appState.grid.weapons.allWeapons[position] && + appState.grid.weapons.allWeapons[position]?.object.id !== weapon.id)) + ) { + post = true + } + + if (post) { + return await api.endpoints.weapons.create({ + weapon: { + party_id: partyId, + weapon_id: weapon.id, + position: position, + mainhand: position == -1, + uncap_level: uncapLevel, + }, + }) + } } function storeGridWeapon(gridWeapon: GridWeapon) {