Commit 41de80af by Tonk

Auto stash before merge of "ejectedExpo" and "origin/ejectedExpo"

parent bad299bd
......@@ -3,20 +3,45 @@ import { View, Row, Icon, Text } from 'native-base';
import { Image, StyleSheet, Platform } from 'react-native';
import { BaseButton, TouchableOpacity } from 'react-native-gesture-handler';
import { color, theme } from '../constants/Styles';
import { connect } from 'react-redux';
import { getCurrentSelectedShadow } from '../reduxStore/actions/currentSelectedAction';
class MeterCard extends Component {
state = {
isPowerOn: false,
};
getShadow = async () => {
const deviceId = this.props.item.deviceId;
await this.props.getCurrentSelectedShadow(deviceId);
};
componentDidMount = async () => {
await this.getShadow();
console.log('meter props', this.props);
};
componentDidUpdate = async (prevProps, prevState) => {
if (prevProps.shadow !== this.props.shadow) {
await this.setInitState();
}
};
setInitState = async () => {
const { shadow } = this.props;
this.setState({
isPowerOn: shadow.SM1.BK_S,
});
};
render() {
const item = this.props.item;
const { isPowerOn } = this.state;
return Platform.OS === 'android' ? (
<BaseButton onPress={this.props.onPressEachCard} rippleColor={'#fcc5c5'} style={styles.cardContainer}>
<View
accessible
style={[
styles.meterOn,
{ backgroundColor: item.isOn ? 'rgba(65, 204, 0, 0.59)' : 'rgba(223, 0, 0, 0.59)' },
{ backgroundColor: isPowerOn === 1 ? 'rgba(65, 204, 0, 0.59)' : 'rgba(223, 0, 0, 0.59)' },
]}
>
<Text style={[theme.smDescription, theme.textWhite]}>{item.isOn ? 'ON' : 'OFF'}</Text>
<Text style={[theme.smDescription, theme.textWhite]}>{isPowerOn === 1 ? 'ON' : 'OFF'}</Text>
</View>
<View style={[theme.centerContainer]}>
{item.img ? (
......@@ -54,10 +79,10 @@ class MeterCard extends Component {
<View
style={[
styles.meterOn,
{ backgroundColor: item.isOn ? 'rgba(65, 204, 0, 0.59)' : 'rgba(223, 0, 0, 0.59)' },
{ backgroundColor: isPowerOn === 1 ? 'rgba(65, 204, 0, 0.59)' : 'rgba(223, 0, 0, 0.59)' },
]}
>
<Text style={[theme.smDescription, theme.textWhite]}>{item.isOn ? 'ON' : 'OFF'}</Text>
<Text style={[theme.smDescription, theme.textWhite]}>{isPowerOn === 1 ? 'ON' : 'OFF'}</Text>
</View>
<View style={[theme.centerContainer]}>
{item.img ? (
......@@ -98,7 +123,18 @@ class MeterCard extends Component {
);
}
}
export default MeterCard;
const mapStateToProps = state => ({
shadow: state.currentSelectedDeviceReducer.shadow,
});
const mapDispatchToProps = {
getCurrentSelectedShadow,
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(MeterCard);
const styles = StyleSheet.create({
meterOn: {
......
......@@ -30,12 +30,8 @@ export const getCurrentSelectedShadowAction = shadow => ({
shadow,
});
export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId;
const URL = `${baseURL}/shadow/${deviceId || selectedDeviceId}`;
export const getCurrentSelectedShadow = deviceId => async dispatch => {
const URL = `${baseURL}/shadow/${deviceId}`;
const idToken = await app.auth().currentUser.getIdToken(true);
const options = {
headers: { Authorization: `Token ${idToken}` },
......@@ -48,39 +44,22 @@ export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) =
},
} = await axios(options);
dispatch(getCurrentSelectedShadowAction(value || null));
await dispatch(getCurrentSelectedShadowAction(value || null));
} catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
}
};
export const getCurrentSelectedData = deviceId => async dispatch => {
const URL = `${baseURL}/shadow/${deviceId}`;
const idToken = await app.auth().currentUser.getIdToken(true);
const options = {
headers: { Authorization: `Token ${idToken}` },
url: URL,
};
try {
//FIRESTORE
dispatch(loadingAction(true));
const currentSelectedDevice = await fireStore
.collection('device')
.doc(deviceId)
.get();
const currentSelectedDeviceData = await currentSelectedDevice.data();
const currentSelectedDeviceDataMoreInfo = { ...currentSelectedDeviceData, deviceId: currentSelectedDevice.id };
//CLOUD FUNCTION :: GET SHADOW
const {
data: {
shadow: { value },
},
} = await axios(options);
dispatch(getCurrentSelectedShadowAction(value || null));
dispatch(getCurrentSelectedDataAction(currentSelectedDeviceDataMoreInfo));
dispatch(loadingAction(false));
} catch (error) {
......
......@@ -6,7 +6,7 @@ import { TouchableOpacity } from 'react-native-gesture-handler';
import { connect } from 'react-redux';
import {
getCurrentSelectedData,
// getCurrentSelectedShadow,
getCurrentSelectedShadow,
loadingAction,
setMainStatus,
} from '../../../reduxStore/actions/currentSelectedAction';
......@@ -55,6 +55,7 @@ class SmartMeterDetailScreen extends Component {
const deviceId = this.props.navigation.getParam('deviceId');
await this.props.getCurrentSelectedData(deviceId);
await this.props.getTimers();
await this.props.getCurrentSelectedShadow(deviceId);
};
componentDidMount = async () => {
......@@ -77,6 +78,20 @@ class SmartMeterDetailScreen extends Component {
this.setSubBreakersState();
}
};
handleToggle = value => {
const deviceId = this.props.navigation.getParam('deviceId');
this.props.setMainStatus(value);
let test = setInterval(() => {
this.props.getCurrentSelectedShadow(deviceId);
console.log('getShadow');
}, 2000);
console.log('handle');
setTimeout(() => {
clearInterval(test);
console.log('stop checking');
}, 6000);
};
componentWillUnmount = () => {
this._mcbLinksListMounted = false;
......@@ -116,8 +131,8 @@ class SmartMeterDetailScreen extends Component {
</Left>
<Right>
<Switch
value={this.props.shadow ? (this.props.shadow.SM1.BK_S === 1 ? true : false) : false}
onValueChange={value => this.props.setMainStatus(value)}
value={isPowerOn === 1 ? true : false}
onValueChange={value => this.handleToggle(value)}
/>
</Right>
</Row>
......@@ -340,7 +355,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = {
getCurrentSelectedData,
// getCurrentSelectedShadow,
getCurrentSelectedShadow,
loadingAction,
loadingTimersAction,
getTimers,
......
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