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