1
0
Fork 0
web2019/static/js/shop/CrateList.jsx

37 lines
1.3 KiB
JavaScript

import React from 'react'
import {Accordion} from "react-bootstrap";
import {Crate} from "./Crate.jsx";
import {useShopStore} from "./shop_store";
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,
}));
return (
<Accordion defaultActiveKey={active_crate}>
{crates.map((crate, index) =>
<Accordion.Item eventKey={crate.id} key={"accordion"+crate.id} >
<Accordion.Header onClick={() => setActiveCrate(crate.id)}>Crate #{`${index}`}</Accordion.Header>
<Accordion.Body>
<Crate crate_index={index}/>
</Accordion.Body>
</Accordion.Item>
)}
<Accordion.Item eventKey="last">
<Accordion.Header>
Add new crate
<button style={{width: "32px"}} onClick={onAddCrate}>
<img src="/images/shop/icon-add.svg" alt="add" />
</button>
</Accordion.Header>
</Accordion.Item>
</Accordion>)
}