Commit da24617a by HaOuiha

.

parent d76df389
......@@ -151,7 +151,22 @@ export const getCurrentSelectedData = (deviceId, showLoading) => async dispatch
}
};
export const updateSubscriptionToStore = newWholeShadow => async dispatch => {
export const updateSubscriptionToStore = subscriptionData => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { shadow, breakerStatus } = currentSelectedDeviceReducer;
console.log('subscriptionData', subscriptionData);
console.log('s', shadow);
console.log('b', breakerStatus);
['SM1', 'ML1', 'ML2', 'ML3', 'ML4'].map(item => subscriptionData.hasOwnProperty(item));
console.log(
['SM1', 'ML1', 'ML2', 'ML3', 'ML4']
.map(item => subscriptionData.hasOwnProperty(item))
.some(item => item === true)
);
const tempBreakersStatus = _.pick(newWholeShadow, ['SM1', 'ML1', 'ML2', 'ML3', 'ML4']);
const breakersStatus = { ...tempBreakersStatus, SM1: { BK_S: tempBreakersStatus.SM1.BK_S } };
......
......@@ -54,7 +54,7 @@ class SmartMeterDetailScreen extends Component {
{ name: 'Arcing Fault', limit: 1000, value: 0, unit: '' },
],
shadow: null,
// shadow: null,
};
_mcbLinksListMounted = false;
......@@ -67,10 +67,10 @@ class SmartMeterDetailScreen extends Component {
document: SUBSCRIBE_SHADOW,
variables: { deviceid: this.deviceId },
updateQuery: (prev, { subscriptionData }) => {
this.setState((prevState, props) => ({
shadow: { ...prevState.shadow, ...subscriptionData.data.shadowUpdated.data },
}));
this.props.updateSubscriptionToStore(this.state.shadow);
// this.setState((prevState, props) => ({
// shadow: { ...prevState.shadow, ...subscriptionData.data.shadowUpdated.data },
// }));
this.props.updateSubscriptionToStore(subscriptionData.data.shadowUpdated.data);
},
});
};
......@@ -81,8 +81,6 @@ class SmartMeterDetailScreen extends Component {
};
componentDidMount = async () => {
// console.log(this.state);
// console.log(this.props);
await this.getData();
this.setState({ shadow: this.props.data.shadow.data });
this.subscribeToNewShadow(this.props.data.subscribeToMore);
......@@ -107,7 +105,7 @@ class SmartMeterDetailScreen extends Component {
}
if (prevProps.isFocused !== this.props.isFocused) {
this.props.isFocused === true && this.subscribeToNewShadow(this.props.data.subscribeToMore);
this.props.isFocused === false && this.unsubscribeShadow();
this.props.isFocused === false && this.unsubscribeShadow && this.unsubscribeShadow();
}
if (prevProps.shadow !== this.props.shadow) {
this.setState({
......@@ -125,16 +123,18 @@ class SmartMeterDetailScreen extends Component {
};
handleToggle = async value => {
this.unsubscribeShadow && this.unsubscribeShadow();
this.setState({ isWaiting: true });
await this.props.setMainStatus(value);
this.setState({ isWaiting: false });
this.subscribeToNewShadow(this.props.data.subscribeToMore);
};
componentWillUnmount = () => {
//reset new loading to redux; fix blink screen
this.props.loadingAction(true);
this.props.loadingTimersAction(true);
this.unsubscribeShadow();
this.unsubscribeShadow && this.unsubscribeShadow();
};
setMainCardData = async () => {
......@@ -268,9 +268,11 @@ class SmartMeterDetailScreen extends Component {
const renderSubBreaker = (subBreaker, indexSubBreakers) => {
const handleOnPressSubBreakerSwitch = async value => {
this.unsubscribeShadow && this.unsubscribeShadow();
this.setState({ isWaiting: true });
await this.props.setSubBreakerStatus(value, indexMcbLinks, indexSubBreakers);
this.setState({ isWaiting: false });
this.subscribeToNewShadow(this.props.data.subscribeToMore);
};
return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment