Commit 54d429fa by HaOuiha

binding value & add loading to gradientbn

parent 9071f391
...@@ -52,6 +52,7 @@ class Login extends Component { ...@@ -52,6 +52,7 @@ class Login extends Component {
Keyboard.dismiss(); Keyboard.dismiss();
}} }}
title={'login'} title={'login'}
loading={this.props.loading}
/> />
</> </>
); );
......
...@@ -2,6 +2,8 @@ import React from 'react'; ...@@ -2,6 +2,8 @@ import React from 'react';
import LinearGradient from 'react-native-linear-gradient'; import LinearGradient from 'react-native-linear-gradient';
import { color } from '../constants/Styles'; import { color } from '../constants/Styles';
import { Button, Text } from 'native-base'; import { Button, Text } from 'native-base';
import { ActivityIndicator } from 'react-native';
const GradientBtn = props => { const GradientBtn = props => {
return ( return (
<LinearGradient <LinearGradient
...@@ -10,8 +12,12 @@ const GradientBtn = props => { ...@@ -10,8 +12,12 @@ const GradientBtn = props => {
end={{ x: 1.0, y: 0.0 }} end={{ x: 1.0, y: 0.0 }}
style={{ borderRadius: 100, alignItems: 'center', marginTop: 30 }} style={{ borderRadius: 100, alignItems: 'center', marginTop: 30 }}
> >
<Button full transparent onPress={props.onPress}> <Button full transparent onPress={props.onPress} disabled={props.loading}>
{props.loading ? (
<ActivityIndicator color={color.white} />
) : (
<Text style={{ color: color.white, fontFamily: 'Avenir-Roman' }}>{props.title.toUpperCase()}</Text> <Text style={{ color: color.white, fontFamily: 'Avenir-Roman' }}>{props.title.toUpperCase()}</Text>
)}
</Button> </Button>
</LinearGradient> </LinearGradient>
); );
......
...@@ -12,7 +12,8 @@ const MeterCard = ({ item, onPressEachCard }) => { ...@@ -12,7 +12,8 @@ const MeterCard = ({ item, onPressEachCard }) => {
styles.meterOn, styles.meterOn,
{ backgroundColor: item.breakerStatus === 1 ? 'rgba(65, 204, 0, 0.59)' : 'rgba(223, 0, 0, 0.59)' }, { backgroundColor: item.breakerStatus === 1 ? 'rgba(65, 204, 0, 0.59)' : 'rgba(223, 0, 0, 0.59)' },
]} ]}
></View> />
{/* <View style={[styles.meterOnInner, { backgroundColor: item.breakerStatus === 1 ? 'rgba(65, 204, 0, 0.2)' : 'rgba(223, 0, 0, 0.2)'}]} /> */}
<View style={[theme.centerContainer, { paddingLeft: 10 }]}> <View style={[theme.centerContainer, { paddingLeft: 10 }]}>
{item.img ? ( {item.img ? (
<Image source={{ uri: item.img }} style={styles.meterImgStyle} /> <Image source={{ uri: item.img }} style={styles.meterImgStyle} />
...@@ -25,7 +26,7 @@ const MeterCard = ({ item, onPressEachCard }) => { ...@@ -25,7 +26,7 @@ const MeterCard = ({ item, onPressEachCard }) => {
<View style={[theme.containerWithPadding, { flex: 2 }]}> <View style={[theme.containerWithPadding, { flex: 2 }]}>
<Text style={[theme.smallTitle]}>{item.name}</Text> <Text style={[theme.smallTitle]}>{item.name}</Text>
<Text style={[theme.description, theme.mt1]} numberOfLines={2}> <Text style={[theme.description, theme.mt1]} numberOfLines={2}>
{item.description} {item.description || 'No description'}
</Text> </Text>
</View> </View>
<View style={[theme.rowContainer, { position: 'absolute', top: 10, right: 5 }]}> <View style={[theme.rowContainer, { position: 'absolute', top: 10, right: 5 }]}>
...@@ -57,6 +58,15 @@ const styles = StyleSheet.create({ ...@@ -57,6 +58,15 @@ const styles = StyleSheet.create({
left: 0, left: 0,
bottom: 0, bottom: 0,
width: 10, width: 10,
borderBottomLeftRadius: 8,
borderTopLeftRadius: 8,
position: 'absolute',
},
meterOnInner: {
top: 0,
left: 10,
bottom: 0,
width: 4,
position: 'absolute', position: 'absolute',
}, },
meterImgStyle: { meterImgStyle: {
......
import app, { fireStore } from '../../firebase'; import { fireStore } from '../../firebase';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
export const GET_CURRENT_USER = 'GET_CURRENT_USER'; export const GET_CURRENT_USER = 'GET_CURRENT_USER';
export const GET_CURRENT_USER_LOADING = 'GET_CURRENT_USER_LOADING';
export const getCurrentUserAction = (displayName, email, emailVerified, phoneNumber, uid, photoURL) => ({ export const getCurrentUserAction = (displayName, email, emailVerified, phoneNumber, uid, photoURL) => ({
type: GET_CURRENT_USER, type: GET_CURRENT_USER,
...@@ -13,6 +14,11 @@ export const getCurrentUserAction = (displayName, email, emailVerified, phoneNum ...@@ -13,6 +14,11 @@ export const getCurrentUserAction = (displayName, email, emailVerified, phoneNum
photoURL, photoURL,
}); });
export const getCurrentUserLoadingAction = bool => ({
type: GET_CURRENT_USER_LOADING,
isLoading: bool,
});
export const getCurrentUser = user => async dispatch => { export const getCurrentUser = user => async dispatch => {
try { try {
const appUser = await fireStore const appUser = await fireStore
...@@ -22,9 +28,16 @@ export const getCurrentUser = user => async dispatch => { ...@@ -22,9 +28,16 @@ export const getCurrentUser = user => async dispatch => {
const appUserData = appUser.data(); const appUserData = appUser.data();
const { displayName, email, emailVerified, phoneNumber, photoURL, token } = appUserData; const { displayName, email, emailVerified, phoneNumber, photoURL, token } = appUserData;
//firestore > firebase.user
const isEmailVerified = emailVerified ? emailVerified : user.emailVerified;
if (!isEmailVerified) {
const userRef = fireStore.collection('user').doc(user.uid);
await userRef.update({ emailVerified: isEmailVerified });
}
await AsyncStorage.setItem('token', token); await AsyncStorage.setItem('token', token);
dispatch(getCurrentUserAction(displayName, email, emailVerified, phoneNumber, user.uid, photoURL)); dispatch(getCurrentUserAction(displayName, email, isEmailVerified, phoneNumber, user.uid, photoURL));
} catch (e) { } catch (e) {
alert('getCurrentUser error'); alert('getCurrentUser error');
console.log(e); console.log(e);
...@@ -33,15 +46,17 @@ export const getCurrentUser = user => async dispatch => { ...@@ -33,15 +46,17 @@ export const getCurrentUser = user => async dispatch => {
export const updateUser = userData => async (dispatch, getState) => { export const updateUser = userData => async (dispatch, getState) => {
const { currentUserReducer } = getState(); const { currentUserReducer } = getState();
const { email, emailVerified, uid, photoURL } = currentUserReducer; const { displayName, email, emailVerified, uid, photoURL, phoneNumber } = currentUserReducer;
try { try {
const newDisplayName = userData.displayName; const newDisplayName = userData ? userData.displayName : displayName;
const newPhoneNumber = userData.phoneNumber; const newPhoneNumber = userData ? userData.phoneNumber : phoneNumber;
const userRef = fireStore.collection('user').doc(uid); const userRef = fireStore.collection('user').doc(uid);
await userRef.update({ await userRef.update({
displayName: newDisplayName, displayName: newDisplayName,
email,
emailVerified,
phoneNumber: newPhoneNumber, phoneNumber: newPhoneNumber,
photoURL, photoURL,
}); });
......
...@@ -37,11 +37,6 @@ export const getBreakersStatusAction = breakerStatus => ({ ...@@ -37,11 +37,6 @@ export const getBreakersStatusAction = breakerStatus => ({
breakerStatus, breakerStatus,
}); });
// export const setDesiredSahdowAction = desiredBreakerStatus => ({
// type: SET_DESIRED_BREAKERS_STATUS_SHADOW,
// desiredBreakerStatus,
// });
export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) => { export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState(); const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData } = currentSelectedDeviceReducer; const { currentSelectedData } = currentSelectedDeviceReducer;
...@@ -56,12 +51,30 @@ export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) = ...@@ -56,12 +51,30 @@ export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) =
// const tempBreakersStatus = _.pick(value, ['CMD_MSG', 'SM1', 'MD_STA', 'ML0', 'ML1', 'ML2', 'ML3', 'ML4']); // const tempBreakersStatus = _.pick(value, ['CMD_MSG', 'SM1', 'MD_STA', 'ML0', 'ML1', 'ML2', 'ML3', 'ML4']);
const tempBreakersStatus = _.pick(value, ['SM1', 'ML1', 'ML2', 'ML3', 'ML4']); const tempBreakersStatus = _.pick(value, ['SM1', 'ML1', 'ML2', 'ML3', 'ML4']);
const breakersStatus = { ...tempBreakersStatus, SM1: { BK_S: tempBreakersStatus.SM1.BK_S } }; const breakersStatus = { ...tempBreakersStatus, SM1: { BK_S: tempBreakersStatus.SM1.BK_S } };
// console.log('breakersStatus', breakersStatus);
let shadowTimers = [];
let shadowValue = null;
for (let i = 1; i <= 4; i++) {
for (let j = 1; j <= 8; j++) {
shadowTimers.push(`L${i}B${j}T`);
shadowValue = _.omit(value, [
'CMD_MSG',
'TIME_NOW',
'TIME_ZONE',
'VERSION',
'ML1',
'ML2',
'ML3',
'ML4',
'MAB1T',
...shadowTimers,
]);
}
}
dispatch(getBreakersStatusAction(breakersStatus)); dispatch(getBreakersStatusAction(breakersStatus));
dispatch(getCurrentSelectedShadowAction(value || null)); dispatch(getCurrentSelectedShadowAction(shadowValue || null));
} catch (error) { } catch (error) {
dispatch(errorAction(error.message || error || 'Error')); dispatch(errorAction(error.message || error || 'Error'));
} }
...@@ -70,7 +83,6 @@ export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) = ...@@ -70,7 +83,6 @@ export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) =
export const getCurrentSelectedData = (deviceId, showLoading) => async dispatch => { export const getCurrentSelectedData = (deviceId, showLoading) => async dispatch => {
try { try {
//FIRESTORE //FIRESTORE
showLoading && dispatch(loadingAction(true)); showLoading && dispatch(loadingAction(true));
const currentSelectedDevice = await fireStore const currentSelectedDevice = await fireStore
...@@ -91,8 +103,28 @@ export const getCurrentSelectedData = (deviceId, showLoading) => async dispatch ...@@ -91,8 +103,28 @@ export const getCurrentSelectedData = (deviceId, showLoading) => async dispatch
const tempBreakersStatus = _.pick(value, ['SM1', 'ML1', 'ML2', 'ML3', 'ML4']); const tempBreakersStatus = _.pick(value, ['SM1', 'ML1', 'ML2', 'ML3', 'ML4']);
const breakersStatus = { ...tempBreakersStatus, SM1: { BK_S: tempBreakersStatus.SM1.BK_S } }; const breakersStatus = { ...tempBreakersStatus, SM1: { BK_S: tempBreakersStatus.SM1.BK_S } };
let shadowTimers = [];
let shadowValue = null;
for (let i = 1; i <= 4; i++) {
for (let j = 1; j <= 8; j++) {
shadowTimers.push(`L${i}B${j}T`);
shadowValue = _.omit(value, [
'CMD_MSG',
'TIME_NOW',
'TIME_ZONE',
'VERSION',
'ML1',
'ML2',
'ML3',
'ML4',
'MAB1T',
...shadowTimers,
]);
}
}
dispatch(getBreakersStatusAction(breakersStatus)); dispatch(getBreakersStatusAction(breakersStatus));
dispatch(getCurrentSelectedShadowAction(value || null)); dispatch(getCurrentSelectedShadowAction(shadowValue || null));
dispatch(getCurrentSelectedDataAction(currentSelectedDeviceDataMoreInfo)); dispatch(getCurrentSelectedDataAction(currentSelectedDeviceDataMoreInfo));
showLoading && dispatch(loadingAction(false)); showLoading && dispatch(loadingAction(false));
} catch (error) { } catch (error) {
......
import { GET_CURRENT_USER } from '../actions/cerrentUserAction'; import { GET_CURRENT_USER, GET_CURRENT_USER_LOADING } from '../actions/cerrentUserAction';
const initState = { const initState = {
displayName: '', displayName: '',
...@@ -7,6 +7,7 @@ const initState = { ...@@ -7,6 +7,7 @@ const initState = {
phoneNumber: '', phoneNumber: '',
uid: '', uid: '',
photoURL: '', photoURL: '',
isLoading: false,
}; };
const currentUserReducer = (state = initState, action) => { const currentUserReducer = (state = initState, action) => {
...@@ -21,6 +22,8 @@ const currentUserReducer = (state = initState, action) => { ...@@ -21,6 +22,8 @@ const currentUserReducer = (state = initState, action) => {
uid: action.uid, uid: action.uid,
photoURL: action.photoURL, photoURL: action.photoURL,
}; };
case GET_CURRENT_USER_LOADING:
return { ...state, isLoading: action.isLoading };
default: default:
return state; return state;
} }
......
...@@ -97,9 +97,9 @@ class McbLinkScreen extends React.Component { ...@@ -97,9 +97,9 @@ class McbLinkScreen extends React.Component {
}; };
setSubBreakersState = () => { setSubBreakersState = () => {
const { existedSubBreakersData, shadow, existedConnectedDevice } = this.props; const { existedSubBreakersData, breakerStatus, existedConnectedDevice, shadow } = this.props;
const mcbIndex = this.props.navigation.getParam('mcbIndex'); const mcbIndex = this.props.navigation.getParam('mcbIndex');
const status = shadow[`ML${mcbIndex + 1}`]; const status = breakerStatus[`ML${mcbIndex + 1}`];
let subBreakersInfo = []; let subBreakersInfo = [];
...@@ -145,24 +145,6 @@ class McbLinkScreen extends React.Component { ...@@ -145,24 +145,6 @@ class McbLinkScreen extends React.Component {
await this.props.setSubBreakerStatus(value, mcbIndex, index); await this.props.setSubBreakerStatus(value, mcbIndex, index);
await this.props.getCurrentSelectedShadow(); await this.props.getCurrentSelectedShadow();
this.setState({ isWaiting: false }); this.setState({ isWaiting: false });
// const getShadowInterval = setInterval(async () => {
// this.setState(() => {
// if (this.props.desiredBreakerStatus === this.props.breakerStatus) {
// clearInterval(getShadowInterval);
// return { isWaiting: false };
// } else {
// if (checkedTimes >= 2) {
// clearInterval(getShadowInterval);
// checkedTimes = 0;
// }
// return { isWaiting: false };
// }
// });
// ++checkedTimes;
// await this.props.getCurrentSelectedShadow();
// this.setSubBreakersState();
// }, 3000);
}; };
const { subBreakerStatus, isWaiting } = this.state; const { subBreakerStatus, isWaiting } = this.state;
const subStatus = subBreakerStatus[`L${mcbIndex + 1}B${index + 1}`] === 0 ? false : true; const subStatus = subBreakerStatus[`L${mcbIndex + 1}B${index + 1}`] === 0 ? false : true;
...@@ -604,8 +586,6 @@ const mapStateToProps = state => ({ ...@@ -604,8 +586,6 @@ const mapStateToProps = state => ({
existedConnectedDevice: state.timersReducer.existedConnectedDevice, existedConnectedDevice: state.timersReducer.existedConnectedDevice,
shadow: state.currentSelectedDeviceReducer.shadow, shadow: state.currentSelectedDeviceReducer.shadow,
breakerStatus: state.currentSelectedDeviceReducer.breakerStatus, breakerStatus: state.currentSelectedDeviceReducer.breakerStatus,
// desiredBreakerStatus: state.currentSelectedDeviceReducer.desiredBreakerStatus,
breakerStatus: state.currentSelectedDeviceReducer.breakerStatus,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
......
...@@ -16,15 +16,6 @@ import { isIphoneX } from '../../../utils/isPhoneX'; ...@@ -16,15 +16,6 @@ import { isIphoneX } from '../../../utils/isPhoneX';
import { withNavigationFocus } from 'react-navigation'; import { withNavigationFocus } from 'react-navigation';
import _ from 'lodash'; import _ from 'lodash';
let deviceData = [
{ name: 'AC Volt', limit: 1000, value: 0, unit: 'V' },
{ name: 'AC Current', limit: 1000, value: 0, unit: 'A' },
{ name: 'Watt', limit: 1000, value: 0, unit: 'V' },
{ name: 'Leakage Current', limit: 1000, value: 0, unit: 'mA' },
{ name: 'Units/KWh', limit: 1000, value: 0, unit: '' },
{ name: 'Arcing Fault', limit: 1000, value: 0, unit: '' },
];
class SmartMeterDetailScreen extends Component { class SmartMeterDetailScreen extends Component {
static navigationOptions = ({ navigation }) => { static navigationOptions = ({ navigation }) => {
return { return {
...@@ -50,6 +41,15 @@ class SmartMeterDetailScreen extends Component { ...@@ -50,6 +41,15 @@ class SmartMeterDetailScreen extends Component {
mcbLinksInfo: [], mcbLinksInfo: [],
subBreakersInfo: [], subBreakersInfo: [],
isWaiting: false, isWaiting: false,
deviceData: [
{ name: 'AC Volt', limit: 1000, value: 0, unit: 'V' },
{ name: 'AC Current', limit: 1000, value: 0, unit: 'A' },
{ name: 'Watt', limit: 1000, value: 0, unit: 'V' },
{ name: 'Leakage Current', limit: 1000, value: 0, unit: 'mA' },
{ name: 'Units/KWh', limit: 1000, value: 0, unit: '' },
{ name: 'Arcing Fault', limit: 1000, value: 0, unit: '' },
],
}; };
_mcbLinksListMounted = false; _mcbLinksListMounted = false;
...@@ -60,7 +60,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -60,7 +60,7 @@ class SmartMeterDetailScreen extends Component {
await this.props.getCurrentSelectedData(deviceId, true); await this.props.getCurrentSelectedData(deviceId, true);
await this.props.getTimers(); await this.props.getTimers();
this.getDataInterval = setInterval(() => this.props.getCurrentSelectedData(deviceId), 5000); this.getDataInterval = setInterval(() => this.props.getCurrentSelectedData(deviceId), 6000);
}; };
componentDidMount = async () => { componentDidMount = async () => {
...@@ -91,12 +91,26 @@ class SmartMeterDetailScreen extends Component { ...@@ -91,12 +91,26 @@ class SmartMeterDetailScreen extends Component {
clearInterval(this.getDataInterval); clearInterval(this.getDataInterval);
} }
} }
if (prevProps.shadow !== this.props.shadow) {
this.setState({
deviceData: [
{ name: 'AC Volt', limit: 1000, value: this.props.shadow.SM1.VOLT, unit: 'V' },
{ name: 'AC Current', limit: 1000, value: this.props.shadow.SM1.AMP, unit: 'A' },
{ name: 'Watt', limit: 1000, value: this.props.shadow.SM1.WATT, unit: 'V' },
{ name: 'Leakage Current', limit: 1000, value: this.props.shadow.SM1.LEAK, unit: 'mA' },
{ name: 'Units/KWh', limit: 1000, value: this.props.shadow.SM1.UNIT, unit: '' },
{ name: 'untitled', limit: 1000, value: 0, unit: '' },
],
});
}
}; };
handleToggle = async value => { handleToggle = async value => {
clearInterval(this.getDataInterval);
this.setState({ isWaiting: true }); this.setState({ isWaiting: true });
await this.props.setMainStatus(value); await this.props.setMainStatus(value);
this.setState({ isWaiting: false }); this.setState({ isWaiting: false });
this.getDataInterval = setInterval(() => this.props.getCurrentSelectedData(deviceId), 6000);
}; };
componentWillUnmount = () => { componentWillUnmount = () => {
...@@ -166,7 +180,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -166,7 +180,7 @@ class SmartMeterDetailScreen extends Component {
</Right> </Right>
</Row> </Row>
<Text numberOfLines={2} style={[theme.description, theme.mt1, { fontSize: 14 }]}> <Text numberOfLines={2} style={[theme.description, theme.mt1, { fontSize: 14 }]}>
{description || ''} {description || 'No description'}
</Text> </Text>
<Row style={theme.mt1}> <Row style={theme.mt1}>
<Text style={[theme.description, theme.textDark, { marginRight: 5 }]}> <Text style={[theme.description, theme.textDark, { marginRight: 5 }]}>
...@@ -235,9 +249,11 @@ class SmartMeterDetailScreen extends Component { ...@@ -235,9 +249,11 @@ class SmartMeterDetailScreen extends Component {
const renderSubBreaker = (subBreaker, indexSubBreakers) => { const renderSubBreaker = (subBreaker, indexSubBreakers) => {
const handleOnPressSubBreakerSwitch = async value => { const handleOnPressSubBreakerSwitch = async value => {
clearInterval(this.getDataInterval);
this.setState({ isWaiting: true }); this.setState({ isWaiting: true });
await this.props.setSubBreakerStatus(value, indexMcbLinks, indexSubBreakers); await this.props.setSubBreakerStatus(value, indexMcbLinks, indexSubBreakers);
this.setState({ isWaiting: false }); this.setState({ isWaiting: false });
this.getDataInterval = setInterval(() => this.props.getCurrentSelectedData(deviceId), 6000);
}; };
return ( return (
...@@ -344,7 +360,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -344,7 +360,7 @@ class SmartMeterDetailScreen extends Component {
{(this._mcbLinksListMounted || !isLoadingValues) && this.renderMainDatailsCard()} {(this._mcbLinksListMounted || !isLoadingValues) && this.renderMainDatailsCard()}
{(this._mcbLinksListMounted || !isLoadingValues) && ( {(this._mcbLinksListMounted || !isLoadingValues) && (
<FlatList <FlatList
data={deviceData} data={this.state.deviceData}
renderItem={({ item, index }) => this.renderCards(item, index)} renderItem={({ item, index }) => this.renderCards(item, index)}
contentContainerStyle={{ overflow: 'hidden' }} contentContainerStyle={{ overflow: 'hidden' }}
numColumns={3} numColumns={3}
...@@ -379,10 +395,9 @@ const mapStateToProps = state => ({ ...@@ -379,10 +395,9 @@ const mapStateToProps = state => ({
error: state.timersReducer.error, error: state.timersReducer.error,
existedMcbLinksData: state.timersReducer.existedMcbLinksData, existedMcbLinksData: state.timersReducer.existedMcbLinksData,
existedSubBreakersData: state.timersReducer.existedSubBreakersData, existedSubBreakersData: state.timersReducer.existedSubBreakersData,
// shadow: state.currentSelectedDeviceReducer.shadow, shadow: state.currentSelectedDeviceReducer.shadow,
breakerStatus: state.currentSelectedDeviceReducer.breakerStatus, breakerStatus: state.currentSelectedDeviceReducer.breakerStatus,
// desiredBreakerStatus: state.currentSelectedDeviceReducer.desiredBreakerStatus,
}); });
const mapDispatchToProps = { const mapDispatchToProps = {
......
...@@ -86,7 +86,8 @@ class SmartMeterScreen extends PureComponent { ...@@ -86,7 +86,8 @@ class SmartMeterScreen extends PureComponent {
// !error ? ( // !error ? (
return ( return (
<View style={[theme.container, theme.containerWithPadding]}> <View style={[theme.container]}>
<View style={theme.containerWithPadding}>
<Text style={[theme.smallTitle, theme.textDark, { marginBottom: 10 }]}>Smart Device</Text> <Text style={[theme.smallTitle, theme.textDark, { marginBottom: 10 }]}>Smart Device</Text>
<SearchBar <SearchBar
...@@ -98,6 +99,7 @@ class SmartMeterScreen extends PureComponent { ...@@ -98,6 +99,7 @@ class SmartMeterScreen extends PureComponent {
onChangeText={text => this.updateSearch(text)} onChangeText={text => this.updateSearch(text)}
value={this.state.search} value={this.state.search}
/> />
</View>
<FlatList <FlatList
refreshControl={ refreshControl={
...@@ -110,7 +112,11 @@ class SmartMeterScreen extends PureComponent { ...@@ -110,7 +112,11 @@ class SmartMeterScreen extends PureComponent {
colors={[color.primary]} colors={[color.primary]}
/> />
} }
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }} //iPhoneX BottomSpace = 34 contentContainerStyle={{
paddingBottom: isIphoneX() ? 90 : 55,
paddingHorizontal: 15,
paddingTop: 5,
}} //iPhoneX BottomSpace = 34
data={data} data={data}
extraData={this.props || this.state} extraData={this.props || this.state}
keyExtractor={(item, index) => item.deviceId} keyExtractor={(item, index) => item.deviceId}
......
...@@ -216,15 +216,11 @@ class TimerScreen extends PureComponent { ...@@ -216,15 +216,11 @@ class TimerScreen extends PureComponent {
if (selectedBreaker === 'main') { if (selectedBreaker === 'main') {
const isSuccess = await this.props.createNewTimer(null, null, timerData); const isSuccess = await this.props.createNewTimer(null, null, timerData);
if (isSuccess) { isSuccess && this.resetStateAndProps();
this.resetStateAndProps();
}
} else if (selectedBreaker && selectedSubBreaker) { } else if (selectedBreaker && selectedSubBreaker) {
const isSuccess = await this.props.createNewTimer(selectedBreaker, selectedSubBreaker[0].id, timerData); const isSuccess = await this.props.createNewTimer(selectedBreaker, selectedSubBreaker[0].id, timerData);
if (isSuccess) { isSuccess && this.resetStateAndProps();
this.resetStateAndProps();
}
} else alert('please select (Sub) Breaker'); } else alert('please select (Sub) Breaker');
} }
//Edit MODE //Edit MODE
...@@ -276,8 +272,6 @@ class TimerScreen extends PureComponent { ...@@ -276,8 +272,6 @@ class TimerScreen extends PureComponent {
repeatOn: this.props.selectedTimerData.repeatOn, repeatOn: this.props.selectedTimerData.repeatOn,
}); });
} }
// console.log(this.state);
}; };
componentDidMount = () => { componentDidMount = () => {
...@@ -625,7 +619,7 @@ class TimerScreen extends PureComponent { ...@@ -625,7 +619,7 @@ class TimerScreen extends PureComponent {
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
refreshing={this.props.isLoading} refreshing={this.props.isLoading}
onRefresh={async () => await this.props.getTimers()} onRefresh={this.props.getTimers}
title="Pull to refresh" title="Pull to refresh"
tintColor={color.primary} tintColor={color.primary}
titleColor={color.darkGrey} titleColor={color.darkGrey}
...@@ -636,14 +630,8 @@ class TimerScreen extends PureComponent { ...@@ -636,14 +630,8 @@ class TimerScreen extends PureComponent {
data={this.state.timersData} data={this.state.timersData}
extraData={this.state || this.props} extraData={this.state || this.props}
ListEmptyComponent={() => ( ListEmptyComponent={() => (
<View> <View style={{ flex: 1, flexDirection: 'row', justifyContent: 'center' }}>
<Text <Text style={[theme.modalText, theme.mt2, { paddingHorizontal: 30 }]}>
style={[
theme.modalText,
theme.mt2,
{ flex: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 30 },
]}
>
{this._isMounted ? 'No timers' : ''} {this._isMounted ? 'No timers' : ''}
</Text> </Text>
</View> </View>
...@@ -656,7 +644,6 @@ class TimerScreen extends PureComponent { ...@@ -656,7 +644,6 @@ class TimerScreen extends PureComponent {
/> />
{/* Create & Update Timer Modal */} {/* Create & Update Timer Modal */}
<Modal <Modal
coverScreen coverScreen
swipeArea={45} swipeArea={45}
...@@ -691,10 +678,7 @@ class TimerScreen extends PureComponent { ...@@ -691,10 +678,7 @@ class TimerScreen extends PureComponent {
style={[styles.filterModal]} style={[styles.filterModal]}
position={'bottom'} position={'bottom'}
isOpen={this.state.isFilterVisible} isOpen={this.state.isFilterVisible}
onClosed={() => { onClosed={() => this.props.setEditModalVisible(false)}
// this.resetStateAndProps();
this.props.setEditModalVisible(false);
}}
> >
{this.renderFilterModal()} {this.renderFilterModal()}
</Modal> </Modal>
......
...@@ -6,7 +6,7 @@ import { width } from '../../constants/Layout'; ...@@ -6,7 +6,7 @@ import { width } from '../../constants/Layout';
import app from '../../firebase'; import app from '../../firebase';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { getCurrentUser } from '../../reduxStore/actions/cerrentUserAction'; import { getCurrentUser } from '../../reduxStore/actions/cerrentUserAction';
import { fireStore } from '../../firebase'; // import { fireStore } from '../../firebase';
class AuthLoadingScreen extends Component { class AuthLoadingScreen extends Component {
static navigationOptions = { static navigationOptions = {
...@@ -22,11 +22,7 @@ class AuthLoadingScreen extends Component { ...@@ -22,11 +22,7 @@ class AuthLoadingScreen extends Component {
_isMounted = false; _isMounted = false;
showLogoThenIndicator = () => { showLogoThenIndicator = () => {
setTimeout(() => { setTimeout(() => this._isMounted && this.setState({ isShowImg: false }), 1200); // 1200
if (this._isMounted) {
this.setState({ isShowImg: false });
}
}, 900); // 1200
}; };
bootstrapAsync = async () => { bootstrapAsync = async () => {
...@@ -41,7 +37,7 @@ class AuthLoadingScreen extends Component { ...@@ -41,7 +37,7 @@ class AuthLoadingScreen extends Component {
app.auth().onAuthStateChanged(async user => { app.auth().onAuthStateChanged(async user => {
if (user) { if (user) {
await this.props.getCurrentUser(user); await this.props.getCurrentUser(user);
this.props.navigation.navigate('Main'); await this.props.navigation.navigate('Main');
} }
}); });
} else { } else {
...@@ -86,105 +82,3 @@ export default connect( ...@@ -86,105 +82,3 @@ export default connect(
null, null,
mapDispatchToProps mapDispatchToProps
)(AuthLoadingScreen); )(AuthLoadingScreen);
// const createMockData = () => {
// console.log('writting data');
// // const deviceId = 'iYs6Th9Pkg1vTEDIyPa5';
// // const deviceId = '8998c7d5-4476-41d9-81c6-9ef2dbac2505';
// const deviceId = '267a494c-a6b6-4b74-a952-82ba8d5db783';
// const batch = fireStore.batch();
// /*------------------------------*/
// const mainRef = fireStore.doc(`device/${deviceId}`);
// batch.set(mainRef, main);
// // for (let i = 1; i <= 2; i++) {
// // let mainTimerRef = fireStore
// // .collection('device')
// // .doc(deviceId)
// // .collection('Timers')
// // .doc();
// // batch.set(mainTimerRef, timer);
// // }
// /*------------------------------*/
// for (let i = 1; i <= 4; i++) {
// const mcbLinks = {
// type: 'mcbLink',
// name: `MCB Link ${i}`,
// description: `description ${i}`,
// };
// let mcbLinksRef = fireStore
// .collection('device')
// .doc(deviceId)
// .collection('mcbLinks')
// .doc(i.toString());
// batch.set(mcbLinksRef, mcbLinks);
// }
// /*------------------------------*/
// for (let i = 1; i <= 4; i++) {
// for (let j = 1; j <= 8; j++) {
// let subBreakers = {
// type: 'subBreaker',
// name: `Sub Breaker ${j}`,
// description: `description ${j}`,
// };
// let subBreakersRef = fireStore
// .collection('device')
// .doc(deviceId)
// .collection('mcbLinks')
// .doc(i.toString())
// .collection('subBreakers')
// .doc(j.toString());
// // for (let z = 1; z <= 1; z++) {
// // let subBreakerTimerRef = fireStore
// // .collection('device')
// // .doc(deviceId)
// // .collection('mcbLinks')
// // .doc(i.toString())
// // .collection('subBreakers')
// // .doc(j.toString())
// // .collection('Timers')
// // .doc();
// // batch.set(subBreakerTimerRef, timer);
// // }
// batch.set(subBreakersRef, subBreakers);
// }
// }
// batch.commit();
// };
// const main = {
// type: 'main',
// name: 'Main',
// description: 'description',
// notification: true,
// rcbo: 10,
// };
// const initTime = new Date();
// initTime.setFullYear(2019);
// initTime.setMonth(0);
// initTime.setDate(0);
// initTime.setSeconds(0);
// const timer = {
// isActive: false,
// isPowerOn: false,
// timer: 0,
// repeatOn: [
// { id: 0, isRepeat: false, day: 'Sunday' },
// { id: 1, isRepeat: false, day: 'Monday' },
// { id: 2, isRepeat: false, day: 'Tuesday' },
// { id: 3, isRepeat: false, day: 'Wednesday' },
// { id: 4, isRepeat: false, day: 'Thursday' },
// { id: 5, isRepeat: false, day: 'Friday' },
// { id: 6, isRepeat: false, day: 'Saturday' },
// ],
// };
...@@ -5,7 +5,7 @@ import AsyncStorage from '@react-native-community/async-storage'; ...@@ -5,7 +5,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import LoginForm from '../../components/Form/LoginForm'; import LoginForm from '../../components/Form/LoginForm';
import { KeyboardAvoidingView, View } from 'react-native'; import { KeyboardAvoidingView, View } from 'react-native';
import app from '../../firebase'; import app from '../../firebase';
import { getCurrentUser } from '../../reduxStore/actions/cerrentUserAction'; import { getCurrentUser, getCurrentUserLoadingAction } from '../../reduxStore/actions/cerrentUserAction';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
class LoginScreen extends Component { class LoginScreen extends Component {
...@@ -20,16 +20,21 @@ class LoginScreen extends Component { ...@@ -20,16 +20,21 @@ class LoginScreen extends Component {
}; };
handleSignIn = async values => { handleSignIn = async values => {
this.props.getCurrentUserLoadingAction(true);
const { email, password } = values; const { email, password } = values;
try { try {
const userCredential = await app.auth().signInWithEmailAndPassword(email, password); const userCredential = await app.auth().signInWithEmailAndPassword(email, password);
if (userCredential) { if (userCredential) {
await this.props.getCurrentUser(userCredential.user); await this.props.getCurrentUser(userCredential.user);
if (this.props.emailVerified && this.props.emailVerified === true) {
await AsyncStorage.setItem('alreadyLaunched', 'true'); await AsyncStorage.setItem('alreadyLaunched', 'true');
if (this.state.isCheck === true) { if (this.state.isCheck === true) {
await AsyncStorage.setItem('RememberedLogin', 'true'); await AsyncStorage.setItem('RememberedLogin', 'true');
} }
this.props.navigation.navigate('Main'); this.props.navigation.navigate('Main');
} else {
alert('Please verify your email first!');
}
} }
} catch (error) { } catch (error) {
const errorCode = error.code; const errorCode = error.code;
...@@ -41,8 +46,12 @@ class LoginScreen extends Component { ...@@ -41,8 +46,12 @@ class LoginScreen extends Component {
} else { } else {
alert(errorMessage); alert(errorMessage);
} }
console.log(error);
} }
this.props.getCurrentUserLoadingAction(false);
};
componentDidUpdate = () => {
console.log(this.props.emailVerified);
}; };
render() { render() {
...@@ -50,7 +59,7 @@ class LoginScreen extends Component { ...@@ -50,7 +59,7 @@ class LoginScreen extends Component {
return ( return (
<KeyboardAvoidingView style={theme.introContainer}> <KeyboardAvoidingView style={theme.introContainer}>
<Text style={[theme.title, theme.textDark]}>Login</Text> <Text style={[theme.title, theme.textDark]}>Login</Text>
<LoginForm onSubmit={this.handleSignIn}> <LoginForm onSubmit={this.handleSignIn} loading={this.props.isLoading}>
<View style={[theme.rowContainer, theme.mt1, { justifyContent: 'space-between' }]}> <View style={[theme.rowContainer, theme.mt1, { justifyContent: 'space-between' }]}>
<View style={[theme.rowContainer]}> <View style={[theme.rowContainer]}>
<Icon <Icon
...@@ -82,9 +91,15 @@ class LoginScreen extends Component { ...@@ -82,9 +91,15 @@ class LoginScreen extends Component {
const mapDispatchToProps = { const mapDispatchToProps = {
getCurrentUser, getCurrentUser,
getCurrentUserLoadingAction,
}; };
const mapStateTOProps = state => ({
emailVerified: state.currentUserReducer.emailVerified,
isLoading: state.currentUserReducer.isLoading,
});
export default connect( export default connect(
null, mapStateTOProps,
mapDispatchToProps mapDispatchToProps
)(LoginScreen); )(LoginScreen);
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