Commit f3b65ba8 by Tonk

update

parent 5f57fe0c
......@@ -18,6 +18,7 @@
"lodash": "^4.17.15",
"moment": "^2.24.0",
"native-base": "^2.12.2",
"qs": "^6.8.0",
"react": "^16.9.0",
"react-native": "^0.60.4",
"react-native-barcode-mask": "^1.0.5",
......
import app, { fireStore } from '../../firebase';
import axios from 'axios';
import qs from 'qs';
const baseURL = 'https://us-central1-safetcut-20cdf.cloudfunctions.net';
......@@ -113,6 +114,37 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
}
};
export const setMainStatus = (deviceId, value) => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId;
const URL = `${baseURL}/shadow/${deviceId || selectedDeviceId}`;
const idToken = await app.auth().currentUser.getIdToken(true);
const command = () => {
switch (value) {
case true:
return 'MAIN_ON';
case false:
return 'MAIN_OFF';
}
};
const options = {
method: 'put',
headers: { Authorization: `Token ${idToken}` },
url: URL,
data: { data: { CMD_MSG: { MSG1: command() } } },
contentType: 'application/json',
};
await axios(options)
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
};
// export const getCurrentSelectedData = (deviceId, mcbLinkId, subBreakerId) => (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
......
......@@ -4,7 +4,11 @@ import { color, theme } from '../../../constants/Styles';
import { FlatList, StyleSheet, ActivityIndicator, RefreshControl, ScrollView, Platform } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { connect } from 'react-redux';
import { getCurrentSelectedData, getCurrentSelectedShadow } from '../../../reduxStore/actions/currentSelectedAction';
import {
getCurrentSelectedData,
getCurrentSelectedShadow,
setMainStatus,
} from '../../../reduxStore/actions/currentSelectedAction';
import { getTimers } from '../../../reduxStore/actions/timersAction';
import { isIphoneX } from '../../../utils/isPhoneX';
......@@ -54,10 +58,14 @@ class SmartMeterDetailScreen extends Component {
componentDidMount = async () => {
await this.getData();
console.log('PROPS', this.props);
};
componentDidUpdate = (prevProps, prevState) => {
if (prevProps.currentSelectedData !== this.props.currentSelectedData) {
if (
prevProps.currentSelectedData !== this.props.currentSelectedData ||
prevProps.shadow !== this.props.shadow
) {
this.setMainCardData();
}
if (prevProps.existedMcbLinksData !== this.props.existedMcbLinksData) {
......@@ -80,7 +88,7 @@ class SmartMeterDetailScreen extends Component {
name: currentSelectedData.name,
rcbo: currentSelectedData.rcbo,
isOnline: currentSelectedData.isOnline || false,
isPowerOn: currentSelectedData.isPowerOn || false,
isPowerOn: this.props.shadow.SM1.BK_S,
});
};
......@@ -103,7 +111,12 @@ class SmartMeterDetailScreen extends Component {
<Text style={[theme.smallTitle, { color: color.darkGrey }]}>{name || 'Untitled'}</Text>
</Left>
<Right>
<Switch value={isPowerOn} />
<Switch
value={isPowerOn === 1 ? true : false}
onValueChange={value =>
this.props.setMainStatus(this.props.navigation.getParam('deviceId'), value)
}
/>
</Right>
</Row>
<Text numberOfLines={2} style={[theme.description, theme.mt1, { fontSize: 14 }]}>
......@@ -312,12 +325,14 @@ const mapStateToProps = state => ({
isLoadingList: state.timersReducer.isLoading,
existedMcbLinksData: state.timersReducer.existedMcbLinksData,
existedSubBreakersData: state.timersReducer.existedSubBreakersData,
shadow: state.currentSelectedDeviceReducer.shadow,
});
const mapDispatchToProps = {
getCurrentSelectedData,
getCurrentSelectedShadow,
getTimers,
setMainStatus,
};
export default connect(
......
......@@ -5973,6 +5973,11 @@ punycode@^2.1.0, punycode@^2.1.1:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
qs@^6.8.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.8.0.tgz#87b763f0d37ca54200334cd57bb2ef8f68a1d081"
integrity sha512-tPSkj8y92PfZVbinY1n84i1Qdx75lZjMQYx9WZhnkofyxzw2r7Ho39G3/aEvSUdebxpnnM4LZJCtvE/Aq3+s9w==
qs@~6.5.2:
version "6.5.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
......
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