From e6df70b96a143ccd5488374172cfbaec8b0ae3a4 Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Thu, 7 Dec 2023 17:50:33 +0800 Subject: [PATCH] Add add/delete functionality to crates Signed-off-by: Egor Savkin --- static/js/shop/Cart.jsx | 2 +- static/js/shop/Crate.jsx | 9 ++++++++- static/js/shop/CrateList.jsx | 16 ++++++++++++++-- static/js/shop/Shop.jsx | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/static/js/shop/Cart.jsx b/static/js/shop/Cart.jsx index 9a1b7e5..e85bc94 100644 --- a/static/js/shop/Cart.jsx +++ b/static/js/shop/Cart.jsx @@ -1,6 +1,6 @@ import React from 'react' import {Droppable} from "@hello-pangea/dnd"; -import {cartStyle, nbrOccupiedSlotsInCrate} from "./utils"; +import {cartStyle} from "./utils"; import {ProductCartItem} from "./ProductCartItem.jsx"; import {FakePlaceholder} from "./FakePlaceholder.jsx"; import {FillExtData} from "./options/utils"; diff --git a/static/js/shop/Crate.jsx b/static/js/shop/Crate.jsx index 0b9fabb..805c82f 100644 --- a/static/js/shop/Crate.jsx +++ b/static/js/shop/Crate.jsx @@ -7,12 +7,19 @@ import {CrateWarnings} from "./CrateWarnings.jsx"; * Component that displays the main crate with reminder rules. * It includes and rules */ -export function Crate({data, handleToggleOverlayRemove, handleDeleteItem, handleShowOverlayRemove, handleCardsUpdated, isMobile, isTouch}) { +export function Crate({data, handleToggleOverlayRemove, handleDeleteItem, handleShowOverlayRemove, handleCardsUpdated, isMobile, isTouch, onDelete}) { return (
+
+ Delete crate + +
+
{ + onAddCrate("crate" + Object.entries(crates).length); + } + return ( {Object.entries(crates).map(([crate_id, crate], index) => Crate #{`${index}`} - + )} + + + Add new crate + + + ) } \ No newline at end of file diff --git a/static/js/shop/Shop.jsx b/static/js/shop/Shop.jsx index 41e4d9d..4dd5ed3 100644 --- a/static/js/shop/Shop.jsx +++ b/static/js/shop/Shop.jsx @@ -48,6 +48,8 @@ export class Shop extends PureComponent { this.handleClickOpenImport = this.handleClickOpenImport.bind(this); this.handleLoadCustomConf = this.handleLoadCustomConf.bind(this); this.handleCardsUpdated = this.handleCardsUpdated.bind(this); + this.onAddCrate = this.onAddCrate.bind(this); + this.onDeleteCrate = this.onDeleteCrate.bind(this); this.timer = null; this.timer_remove = null; @@ -81,6 +83,7 @@ export class Shop extends PureComponent { * trigger again this function (componentDidUpdate) and thus, * making an infinite loop. */ + console.log("componentDidUpdate") return; if ( (prevState.columns.crates !== this.state.columns.crates.items) || @@ -493,6 +496,34 @@ export class Shop extends PureComponent { }); } + onAddCrate(id) { + this.setState({ + ...this.state, + columns: { + ...this.state.columns, + crates: { + ...this.state.columns.crates, + [id]: { + crate_type: "rack", + items: [] + }} + } + }); + } + onDeleteCrate(id) { + let new_state = { + ...this.state, + columns: { + ...this.state.columns, + crates: { + ...this.state.columns.crates, + [id]: undefined + } + }}; + delete new_state.columns.crates[id]; + this.setState(new_state); + } + render() { const { @@ -551,6 +582,10 @@ export class Shop extends PureComponent { cratesList={ } summaryPrice={