fix: use API response data for grid local state updates

- use addResult/response directly instead of manually constructing objects
- fixes grid not displaying items until refresh
- API response has proper GridWeapon/Character/Summon structure
This commit is contained in:
Justin Edmund 2025-11-29 05:54:09 -08:00
parent a34e0f939b
commit 782aaf1479

View file

@ -168,16 +168,7 @@
itemAdded = true itemAdded = true
// Update local state with the added weapon // Update local state with the added weapon
weapons = [...weapons, { weapons = [...weapons, addResult]
id: addResult.id || `temp-${Date.now()}`,
position,
object: {
granblueId: firstItem.granblueId,
name: firstItem.name,
element: firstItem.element
},
mainhand: position === -1
}]
} else if (activeTab === GridType.Summon) { } else if (activeTab === GridType.Summon) {
// Use selectedSlot if available, otherwise default to main summon // Use selectedSlot if available, otherwise default to main summon
if (selectedSlot === null) position = -1 if (selectedSlot === null) position = -1
@ -192,17 +183,7 @@
itemAdded = true itemAdded = true
// Update local state with the added summon // Update local state with the added summon
summons = [...summons, { summons = [...summons, addResult]
id: addResult.id || `temp-${Date.now()}`,
position,
object: {
granblueId: firstItem.granblueId,
name: firstItem.name,
element: firstItem.element
},
main: position === -1,
friend: position === 6
}]
} else if (activeTab === GridType.Character) { } else if (activeTab === GridType.Character) {
// Use selectedSlot if available, otherwise default to first slot // Use selectedSlot if available, otherwise default to first slot
if (selectedSlot === null) position = 0 if (selectedSlot === null) position = 0
@ -215,15 +196,7 @@
itemAdded = true itemAdded = true
// Update local state with the added character // Update local state with the added character
characters = [...characters, { characters = [...characters, addResult]
id: addResult.id || `temp-${Date.now()}`,
position,
object: {
granblueId: firstItem.granblueId,
name: firstItem.name,
element: firstItem.element
}
}]
} }
selectedSlot = null // Reset after using selectedSlot = null // Reset after using
@ -311,16 +284,7 @@
}) })
// Add to local state // Add to local state
weapons = [...weapons, { weapons = [...weapons, response]
id: response.id || `temp-${Date.now()}`,
position,
object: {
granblueId: item.granblueId,
name: item.name,
element: item.element
},
mainhand: position === -1
}]
} else if (activeTab === GridType.Summon) { } else if (activeTab === GridType.Summon) {
// Use selectedSlot for first item if available // Use selectedSlot for first item if available
if (i === 0 && selectedSlot !== null && !summons.find(s => s.position === selectedSlot)) { if (i === 0 && selectedSlot !== null && !summons.find(s => s.position === selectedSlot)) {
@ -344,17 +308,7 @@
}) })
// Add to local state // Add to local state
summons = [...summons, { summons = [...summons, response]
id: response.id || `temp-${Date.now()}`,
position,
object: {
granblueId: item.granblueId,
name: item.name,
element: item.element
},
main: position === -1,
friend: position === 6
}]
} else if (activeTab === GridType.Character) { } else if (activeTab === GridType.Character) {
// Use selectedSlot for first item if available // Use selectedSlot for first item if available
if (i === 0 && selectedSlot !== null && !characters.find(c => c.position === selectedSlot)) { if (i === 0 && selectedSlot !== null && !characters.find(c => c.position === selectedSlot)) {
@ -376,15 +330,7 @@
}) })
// Add to local state // Add to local state
characters = [...characters, { characters = [...characters, response]
id: response.id || `temp-${Date.now()}`,
position,
object: {
granblueId: item.granblueId,
name: item.name,
element: item.element
}
}]
} }
} }
} catch (error: any) { } catch (error: any) {