Fix crate list expansion behavior

Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
Egor Savkin 2023-12-13 16:42:18 +08:00
parent 3b1d9fcb56
commit c7314801ed
2 changed files with 11 additions and 2 deletions

View File

@ -16,10 +16,16 @@ export function CrateList() {
setActiveCrate: state.setActiveCrate, setActiveCrate: state.setActiveCrate,
})); }));
return ( return (
<Accordion defaultActiveKey={active_crate}> <Accordion flush activeKey={active_crate} onSelect={(e) => {
// if e === null, that means that an accordion item was collapsed rather than expanded. e will be non-null when an item is expanded
if (e !== null)
setActiveCrate(e);
else
setActiveCrate("")
}}>
{crates.map((crate, index) => {crates.map((crate, index) =>
<Accordion.Item eventKey={crate.id} key={"accordion"+crate.id} > <Accordion.Item eventKey={crate.id} key={"accordion"+crate.id} >
<Accordion.Header onClick={() => setActiveCrate(crate.id)}>Crate #{`${index}`}</Accordion.Header> <Accordion.Header>Crate #{`${index}`}</Accordion.Header>
<Accordion.Body> <Accordion.Body>
<Crate crate_index={index}/> <Crate crate_index={index}/>
</Accordion.Body> </Accordion.Body>

View File

@ -356,6 +356,7 @@ const useCart = ((set, get) => ({
setCrateMode: (id, mode) => { setCrateMode: (id, mode) => {
get()._setCrateMode(id, mode) get()._setCrateMode(id, mode)
get().fillWarnings(id); get().fillWarnings(id);
get().setActiveCrate(crate_to);
}, },
addCardFromBacklog: (crate_to, index_from, index_to, just_mounted) => { addCardFromBacklog: (crate_to, index_from, index_to, just_mounted) => {
@ -363,6 +364,7 @@ const useCart = ((set, get) => ({
if (!dest) return {}; if (!dest) return {};
get()._addCardFromBacklog(dest, index_from, index_to) get()._addCardFromBacklog(dest, index_from, index_to)
get().fillWarnings(dest); get().fillWarnings(dest);
get().setActiveCrate(dest);
if (!just_mounted) { if (!just_mounted) {
get().cardAdded() get().cardAdded()
} }
@ -371,6 +373,7 @@ const useCart = ((set, get) => ({
moveCard: (crate_from, index_from, crate_to, index_to) => { moveCard: (crate_from, index_from, crate_to, index_to) => {
get()._moveCard(crate_from, index_from, crate_to, index_to); get()._moveCard(crate_from, index_from, crate_to, index_to);
get().fillWarnings(crate_to); get().fillWarnings(crate_to);
get().setActiveCrate(crate_to);
if (crate_from !== crate_to) get().fillWarnings(crate_from); if (crate_from !== crate_to) get().fillWarnings(crate_from);
}, },
deleteCard: (crate_id, index) => { deleteCard: (crate_id, index) => {