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-08 17:36:12 +08:00
|
|
|
<Accordion defaultActiveKey={active_crate}>
|
2023-12-11 17:05:35 +08:00
|
|
|
{crates.map((crate, index) =>
|
|
|
|
<Accordion.Item eventKey={crate.id} key={"accordion"+crate.id} >
|
|
|
|
<Accordion.Header onClick={() => setActiveCrate(crate.id)}>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">
|
|
|
|
<Accordion.Header>
|
|
|
|
Add new crate
|
2023-12-11 17:05:35 +08:00
|
|
|
<button style={{width: "32px"}} onClick={onAddCrate}>
|
2023-12-07 17:50:33 +08:00
|
|
|
<img src="/images/shop/icon-add.svg" alt="add" />
|
|
|
|
</button>
|
|
|
|
</Accordion.Header>
|
|
|
|
</Accordion.Item>
|
2023-12-07 17:08:22 +08:00
|
|
|
</Accordion>)
|
|
|
|
}
|