fix edit sidebars to use pane stack push/pop
This commit is contained in:
parent
a02db87988
commit
122b07e827
1 changed files with 26 additions and 38 deletions
|
|
@ -89,17 +89,9 @@ export function openWeaponEditSidebar(weapon: GridWeapon) {
|
||||||
const weaponName = getName(weapon.weapon)
|
const weaponName = getName(weapon.weapon)
|
||||||
const title = weaponName !== 'Details' ? weaponName : 'Edit Weapon'
|
const title = weaponName !== 'Details' ? weaponName : 'Edit Weapon'
|
||||||
|
|
||||||
// Get element for styling
|
// Handler to go back to details view - uses pop() to return to previous pane
|
||||||
const element = getItemElement('weapon', weapon)
|
|
||||||
|
|
||||||
// Keep track of the current weapon state for going back to details
|
|
||||||
let currentWeapon = weapon
|
|
||||||
|
|
||||||
// Handler to go back to details view
|
|
||||||
const goBackToDetails = () => {
|
const goBackToDetails = () => {
|
||||||
// Get the updated weapon from the store if available
|
sidebar.pop()
|
||||||
const updated = partyStore.getWeapon(weapon.id)
|
|
||||||
openDetailsSidebar({ type: 'weapon', item: updated ?? currentWeapon })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for save button - saves updates via partyStore
|
// Handler for save button - saves updates via partyStore
|
||||||
|
|
@ -111,22 +103,24 @@ export function openWeaponEditSidebar(weapon: GridWeapon) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updated = await partyStore.updateWeapon(String(weapon.id), updates)
|
await partyStore.updateWeapon(String(weapon.id), updates)
|
||||||
currentWeapon = updated
|
|
||||||
goBackToDetails()
|
goBackToDetails()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save weapon:', error)
|
console.error('Failed to save weapon:', error)
|
||||||
// Still go back on error - the optimistic update will be visible
|
|
||||||
goBackToDetails()
|
goBackToDetails()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sidebar.openWithComponent(title, EditWeaponSidebar, {
|
// Push onto pane stack instead of replacing
|
||||||
|
sidebar.push({
|
||||||
|
id: `edit-weapon-${weapon.id}`,
|
||||||
|
title,
|
||||||
|
component: EditWeaponSidebar,
|
||||||
|
props: {
|
||||||
weapon,
|
weapon,
|
||||||
onSave: handleSave,
|
onSave: handleSave,
|
||||||
onCancel: goBackToDetails
|
onCancel: goBackToDetails
|
||||||
}, {
|
},
|
||||||
element,
|
|
||||||
onback: goBackToDetails
|
onback: goBackToDetails
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -135,17 +129,9 @@ export function openCharacterEditSidebar(character: GridCharacter) {
|
||||||
const characterName = getName(character.character)
|
const characterName = getName(character.character)
|
||||||
const title = characterName !== 'Details' ? characterName : 'Edit Character'
|
const title = characterName !== 'Details' ? characterName : 'Edit Character'
|
||||||
|
|
||||||
// Get element for styling
|
// Handler to go back to details view - uses pop() to return to previous pane
|
||||||
const element = getItemElement('character', character)
|
|
||||||
|
|
||||||
// Keep track of the current character state for going back to details
|
|
||||||
let currentCharacter = character
|
|
||||||
|
|
||||||
// Handler to go back to details view
|
|
||||||
const goBackToDetails = () => {
|
const goBackToDetails = () => {
|
||||||
// Get the updated character from the store if available
|
sidebar.pop()
|
||||||
const updated = partyStore.getCharacter(character.id)
|
|
||||||
openDetailsSidebar({ type: 'character', item: updated ?? currentCharacter })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for save button - saves updates via partyStore
|
// Handler for save button - saves updates via partyStore
|
||||||
|
|
@ -157,22 +143,24 @@ export function openCharacterEditSidebar(character: GridCharacter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updated = await partyStore.updateCharacter(String(character.id), updates)
|
await partyStore.updateCharacter(String(character.id), updates)
|
||||||
currentCharacter = updated
|
|
||||||
goBackToDetails()
|
goBackToDetails()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save character:', error)
|
console.error('Failed to save character:', error)
|
||||||
// Still go back on error - the optimistic update will be visible
|
|
||||||
goBackToDetails()
|
goBackToDetails()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sidebar.openWithComponent(title, EditCharacterSidebar, {
|
// Push onto pane stack instead of replacing
|
||||||
|
sidebar.push({
|
||||||
|
id: `edit-character-${character.id}`,
|
||||||
|
title,
|
||||||
|
component: EditCharacterSidebar,
|
||||||
|
props: {
|
||||||
character,
|
character,
|
||||||
onSave: handleSave,
|
onSave: handleSave,
|
||||||
onCancel: goBackToDetails
|
onCancel: goBackToDetails
|
||||||
}, {
|
},
|
||||||
element,
|
|
||||||
onback: goBackToDetails
|
onback: goBackToDetails
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue