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 b3c4110ceb
commit f279bdbc58
1 changed files with 16 additions and 7 deletions

View File

@ -542,6 +542,7 @@ class ProductCartItem extends React.PureComponent {
onToggleWarning: PropTypes.func, onToggleWarning: PropTypes.func,
onToggleOverlayRemove: PropTypes.func, onToggleOverlayRemove: PropTypes.func,
onClickRemoveItem: PropTypes.func, onClickRemoveItem: PropTypes.func,
onCardUpdate: PropTypes.func,
shouldTooltipWarningClassInverted: PropTypes.bool, shouldTooltipWarningClassInverted: PropTypes.bool,
}; };
} }
@ -625,6 +626,7 @@ class ProductCartItem extends React.PureComponent {
index, index,
ext_data, ext_data,
shouldTooltipWarningClassInverted, shouldTooltipWarningClassInverted,
onCardUpdate,
} = this.props; } = this.props;
let warning, options, options_data; let warning, options, options_data;
@ -725,12 +727,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) }
@ -859,6 +861,7 @@ class Cart extends React.PureComponent {
onToggleWarning: PropTypes.func, onToggleWarning: PropTypes.func,
onToggleOverlayRemove: PropTypes.func, onToggleOverlayRemove: PropTypes.func,
onClickRemoveItem: PropTypes.func, onClickRemoveItem: PropTypes.func,
onCardUpdate: PropTypes.func,
}; };
} }
@ -872,6 +875,7 @@ class Cart extends React.PureComponent {
onToggleWarning, onToggleWarning,
onToggleOverlayRemove, onToggleOverlayRemove,
onClickRemoveItem, onClickRemoveItem,
onCardUpdate,
} = this.props; } = this.props;
const nbrOccupied = nbrOccupiedSlotsInCrate(data.items); const nbrOccupied = nbrOccupiedSlotsInCrate(data.items);
@ -899,6 +903,7 @@ class Cart extends React.PureComponent {
onToggleWarning={onToggleWarning} onToggleWarning={onToggleWarning}
onToggleOverlayRemove={onToggleOverlayRemove} onToggleOverlayRemove={onToggleOverlayRemove}
onClickRemoveItem={onClickRemoveItem} onClickRemoveItem={onClickRemoveItem}
onCardUpdate={onCardUpdate}
model={item}> model={item}>
</ProductCartItem> </ProductCartItem>
); );
@ -1670,6 +1675,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;
} }
@ -1706,9 +1712,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) {
@ -1724,6 +1728,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,
@ -2102,7 +2110,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 {
@ -2492,7 +2500,8 @@ class Shop extends React.PureComponent {
onToggleProgress={this.handleToggleItemProgress} onToggleProgress={this.handleToggleItemProgress}
onToggleWarning={this.handleToggleItemWarning} onToggleWarning={this.handleToggleItemWarning}
onToggleOverlayRemove={this.handleToggleOverlayRemove} onToggleOverlayRemove={this.handleToggleOverlayRemove}
onClickRemoveItem={this.handleDeleteItem}> onClickRemoveItem={this.handleDeleteItem}
onCardUpdate={this.handleCardsUpdated}>
</Cart> </Cart>
} }
rules={Object.values(rules).filter(rule => rule)}> rules={Object.values(rules).filter(rule => rule)}>