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 17:35:17 +08:00
|
|
|
<Accordion id="accordion_crates" flush activeKey={active_crate} onSelect={(e) => {
|
2023-12-13 16:42:18 +08:00
|
|
|
// 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) =>
|
2023-12-14 14:17:18 +08:00
|
|
|
<Accordion.Item eventKey={crate.id} key={"accordion"+crate.id} className="accordion_crates_item">
|
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-13 17:35:17 +08:00
|
|
|
<Accordion.Item eventKey="last" id="accordion_crates_add">
|
2023-12-13 15:17:14 +08:00
|
|
|
<Accordion.Header onClick={onAddCrate}>
|
2023-12-07 17:50:33 +08:00
|
|
|
Add new crate
|
|
|
|
</Accordion.Header>
|
|
|
|
</Accordion.Item>
|
2023-12-07 17:08:22 +08:00
|
|
|
</Accordion>)
|
|
|
|
}
|