diff --git a/components/WeaponGrid/index.tsx b/components/WeaponGrid/index.tsx index 4dbdc346..f5dc668c 100644 --- a/components/WeaponGrid/index.tsx +++ b/components/WeaponGrid/index.tsx @@ -152,19 +152,38 @@ 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) { - if (gridWeapon.position == -1) { + if (gridWeapon.position === -1) { appState.grid.weapons.mainWeapon = gridWeapon appState.party.element = gridWeapon.object.element } else { @@ -183,9 +202,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 +212,9 @@ const WeaponGrid = (props: Props) => { } }) + // Store new character in state + storeGridWeapon(response.data.grid_weapon) + // Reset conflict resetConflict()