1
0
Fork 0

Fix cards state being not updated on touchables

Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
Egor Savkin 2023-09-25 14:51:58 +08:00
parent 1a0b613044
commit acdaeda699
1 changed files with 16 additions and 6 deletions

View File

@ -542,6 +542,7 @@ class ProductCartItem extends React.PureComponent {
onToggleOverlayRemove: PropTypes.func, onToggleOverlayRemove: PropTypes.func,
onClickRemoveItem: PropTypes.func, onClickRemoveItem: PropTypes.func,
onClickItem: PropTypes.func, onClickItem: PropTypes.func,
onCardUpdate: PropTypes.func,
}; };
} }
@ -593,6 +594,7 @@ class ProductCartItem extends React.PureComponent {
data, data,
index, index,
ext_data, ext_data,
onCardUpdate,
} = this.props; } = this.props;
let warning, options, options_data; let warning, options, options_data;
@ -710,12 +712,12 @@ class ProductCartItem extends React.PureComponent {
construct: ((outvar, value) => { construct: ((outvar, value) => {
// console.log("construct", outvar, value, options_data); // console.log("construct", outvar, value, options_data);
options_data[outvar] = value; options_data[outvar] = value;
this.setState(options_data); onCardUpdate();
}), }),
update: ((outvar, value) => { update: ((outvar, value) => {
// console.log("update", outvar, value, options_data); // console.log("update", outvar, value, options_data);
if (outvar in options_data) options_data[outvar] = value; if (outvar in options_data) options_data[outvar] = value;
this.setState(options_data); onCardUpdate();
}) })
}} }}
/>) : null) } />) : null) }
@ -848,6 +850,7 @@ class Cart extends React.PureComponent {
data: PropTypes.object.isRequired, data: PropTypes.object.isRequired,
onToggleOverlayRemove: PropTypes.func, onToggleOverlayRemove: PropTypes.func,
onClickRemoveItem: PropTypes.func, onClickRemoveItem: PropTypes.func,
onCardUpdate: PropTypes.func,
onClickItem: PropTypes.func, onClickItem: PropTypes.func,
}; };
} }
@ -862,6 +865,7 @@ class Cart extends React.PureComponent {
onToggleOverlayRemove, onToggleOverlayRemove,
onClickRemoveItem, onClickRemoveItem,
onClickItem, onClickItem,
onCardUpdate,
} = this.props; } = this.props;
const products = data.items.map((item, index) => { const products = data.items.map((item, index) => {
@ -883,6 +887,7 @@ class Cart extends React.PureComponent {
ext_data={ext_data} ext_data={ext_data}
onToggleOverlayRemove={onToggleOverlayRemove} onToggleOverlayRemove={onToggleOverlayRemove}
onClickRemoveItem={onClickRemoveItem} onClickRemoveItem={onClickRemoveItem}
onCardUpdate={onCardUpdate}
onClickItem={onClickItem} onClickItem={onClickItem}
model={item}> model={item}>
</ProductCartItem> </ProductCartItem>
@ -1654,6 +1659,7 @@ class Shop extends React.PureComponent {
this.handleClickShowOrder = this.handleClickShowOrder.bind(this); this.handleClickShowOrder = this.handleClickShowOrder.bind(this);
this.handleClickOpenImport = this.handleClickOpenImport.bind(this); this.handleClickOpenImport = this.handleClickOpenImport.bind(this);
this.handleLoadCustomConf = this.handleLoadCustomConf.bind(this); this.handleLoadCustomConf = this.handleLoadCustomConf.bind(this);
this.handleCardsUpdated = this.handleCardsUpdated.bind(this);
this.timer = null; this.timer = null;
this.timer_remove = null; this.timer_remove = null;
@ -1691,9 +1697,7 @@ class Shop extends React.PureComponent {
(prevState.columns.cart.items !== this.state.columns.cart.items) || (prevState.columns.cart.items !== this.state.columns.cart.items) ||
(prevState.currentMode !== this.state.currentMode) (prevState.currentMode !== this.state.currentMode)
) { ) {
this.checkAlerts( this.checkAlerts(this.state.columns.cart.items);
prevState.columns.cart.items,
this.state.columns.cart.items);
} }
if (this.state.newCardJustAdded) { if (this.state.newCardJustAdded) {
@ -1709,6 +1713,10 @@ class Shop extends React.PureComponent {
clearTimeout(this.timer); clearTimeout(this.timer);
} }
handleCardsUpdated() {
this.checkAlerts(this.state.columns.cart.items);
}
handleCrateModeChange(mode) { handleCrateModeChange(mode) {
this.setState({ this.setState({
currentMode: mode, currentMode: mode,
@ -2052,7 +2060,7 @@ class Shop extends React.PureComponent {
}); });
} }
checkAlerts(prevItems, newItems) { checkAlerts(newItems) {
console.log('--- START CHECKING CRATE WARNING ---'); console.log('--- START CHECKING CRATE WARNING ---');
const { const {
@ -2444,6 +2452,8 @@ class Shop extends React.PureComponent {
onToggleOverlayRemove={this.handleToggleOverlayRemove} onToggleOverlayRemove={this.handleToggleOverlayRemove}
onClickRemoveItem={this.handleDeleteItem} onClickRemoveItem={this.handleDeleteItem}
onClickItem={this.handleShowOverlayRemove}> onClickItem={this.handleShowOverlayRemove}>
onClickRemoveItem={this.handleDeleteItem}
onCardUpdate={this.handleCardsUpdated}>
</Cart> </Cart>
} }
rules={Object.values(rules).filter(rule => rule)}> rules={Object.values(rules).filter(rule => rule)}>