2023-12-07 17:08:22 +08:00
|
|
|
import React from 'react'
|
|
|
|
import {Accordion} from "react-bootstrap";
|
2023-12-12 18:21:09 +08:00
|
|
|
import {Crate} from "./Crate";
|
2023-12-11 17:05:35 +08:00
|
|
|
import {useShopStore} from "./shop_store";
|
2023-12-07 17:08:22 +08:00
|
|
|
|
2023-12-11 17:05:35 +08:00
|
|
|
export function CrateList() {
|
|
|
|
const {
|
|
|
|
crates,
|
|
|
|
active_crate,
|
|
|
|
onAddCrate,
|
|
|
|
setActiveCrate,
|
|
|
|
} = useShopStore(state=> ({
|
|
|
|
crates: state.crates,
|
|
|
|
active_crate: state.active_crate,
|
|
|
|
onAddCrate: state.newCrate,
|
|
|
|
setActiveCrate: state.setActiveCrate,
|
|
|
|
}));
|
2023-12-07 17:08:22 +08:00
|
|
|
return (
|
2023-12-13 16:42:18 +08:00
|
|
|
<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("")
|
|
|
|
}}>
|
2023-12-11 17:05:35 +08:00
|
|
|
{crates.map((crate, index) =>
|
|
|
|
<Accordion.Item eventKey={crate.id} key={"accordion"+crate.id} >
|
2023-12-13 16:42:18 +08:00
|
|
|
<Accordion.Header>Crate #{`${index}`}</Accordion.Header>
|
2023-12-07 17:08:22 +08:00
|
|
|
<Accordion.Body>
|
2023-12-11 17:05:35 +08:00
|
|
|
<Crate crate_index={index}/>
|
2023-12-07 17:08:22 +08:00
|
|
|
</Accordion.Body>
|
|
|
|
</Accordion.Item>
|
|
|
|
)}
|
2023-12-07 17:50:33 +08:00
|
|
|
<Accordion.Item eventKey="last">
|
2023-12-13 15:17:14 +08:00
|
|
|
<Accordion.Header onClick={onAddCrate}>
|
2023-12-07 17:50:33 +08:00
|
|
|
Add new crate
|
2023-12-13 15:17:14 +08:00
|
|
|
<img src="/images/shop/icon-add.svg" alt="add" width="32px"/>
|
2023-12-07 17:50:33 +08:00
|
|
|
</Accordion.Header>
|
|
|
|
</Accordion.Item>
|
2023-12-07 17:08:22 +08:00
|
|
|
</Accordion>)
|
|
|
|
}
|