Don't POST if the user is adding the same weapon to a position

This commit is contained in:
Justin Edmund 2023-01-29 23:36:57 -08:00
parent fa6b312f06
commit 05df606ea4

View file

@ -152,6 +152,24 @@ const WeaponGrid = (props: Props) => {
if (weapon.uncap.ulb) uncapLevel = 5 if (weapon.uncap.ulb) uncapLevel = 5
else if (weapon.uncap.flb) uncapLevel = 4 else if (weapon.uncap.flb) uncapLevel = 4
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({ return await api.endpoints.weapons.create({
weapon: { weapon: {
party_id: partyId, party_id: partyId,
@ -162,6 +180,7 @@ const WeaponGrid = (props: Props) => {
}, },
}) })
} }
}
function storeGridWeapon(gridWeapon: GridWeapon) { function storeGridWeapon(gridWeapon: GridWeapon) {
if (gridWeapon.position === -1) { if (gridWeapon.position === -1) {