2023-12-07 17:08:22 +08:00
|
|
|
import React from 'react'
|
|
|
|
import {Accordion} from "react-bootstrap";
|
|
|
|
import {Crate} from "./Crate.jsx";
|
|
|
|
|
2023-12-08 17:36:12 +08:00
|
|
|
export function CrateList({crates, active_crate, isMobile, isTouch, onAddCrate, onDeleteCrate, onModeChange, onCrateSelect}) {
|
2023-12-07 17:50:33 +08:00
|
|
|
const onClickAdd = (_) => {
|
|
|
|
onAddCrate("crate" + Object.entries(crates).length);
|
|
|
|
}
|
|
|
|
|
2023-12-07 17:08:22 +08:00
|
|
|
return (
|
2023-12-08 17:36:12 +08:00
|
|
|
<Accordion defaultActiveKey={active_crate}>
|
2023-12-07 17:08:22 +08:00
|
|
|
{Object.entries(crates).map(([crate_id, crate], index) =>
|
2023-12-08 17:36:12 +08:00
|
|
|
<Accordion.Item eventKey={crate_id} key={`crate${index}`} >
|
|
|
|
<Accordion.Header onClick={() => onCrateSelect(crate_id)}>Crate #{`${index}`}</Accordion.Header>
|
2023-12-07 17:08:22 +08:00
|
|
|
<Accordion.Body>
|
2023-12-08 16:39:28 +08:00
|
|
|
<Crate
|
|
|
|
data={{id: crate_id, ...crate}}
|
|
|
|
isTouch={isTouch}
|
|
|
|
isMobile={isMobile}
|
|
|
|
onDelete={onDeleteCrate}
|
|
|
|
onModeChange={(new_mode) => onModeChange(crate_id, new_mode)}
|
|
|
|
/>
|
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
|
|
|
|
<button style={{width: "32px"}} onClick={onClickAdd}>
|
|
|
|
<img src="/images/shop/icon-add.svg" alt="add" />
|
|
|
|
</button>
|
|
|
|
</Accordion.Header>
|
|
|
|
</Accordion.Item>
|
2023-12-07 17:08:22 +08:00
|
|
|
</Accordion>)
|
|
|
|
}
|