Commit afaf941c by Tonk

Merge branch 'injectedFirebase' into ejectedExpo

parents d8dd88a4 4a7df4f1
...@@ -44,15 +44,15 @@ const createMockData = () => { ...@@ -44,15 +44,15 @@ const createMockData = () => {
const mainRef = fireStore.doc(`device/${deviceId}`); const mainRef = fireStore.doc(`device/${deviceId}`);
batch.set(mainRef, main); batch.set(mainRef, main);
// for (let i = 1; i <= 2; i++) { for (let i = 1; i <= 2; i++) {
// let mainTimerRef = fireStore let mainTimerRef = fireStore
// .collection('device') .collection('device')
// .doc(deviceId) .doc(deviceId)
// .collection('Timers') .collection('Timers')
// .doc(); .doc();
// batch.set(mainTimerRef, timer); batch.set(mainTimerRef, timer);
// } }
/*------------------------------*/ /*------------------------------*/
for (let i = 1; i <= 4; i++) { for (let i = 1; i <= 4; i++) {
const mcbLinks = { const mcbLinks = {
...@@ -66,17 +66,17 @@ const createMockData = () => { ...@@ -66,17 +66,17 @@ const createMockData = () => {
.collection('mcbLinks') .collection('mcbLinks')
.doc(i.toString()); .doc(i.toString());
for (let z = 1; z <= 1; z++) { // for (let z = 1; z <= 1; z++) {
let mcbLinkTimerRef = fireStore // let mcbLinkTimerRef = fireStore
.collection('device') // .collection('device')
.doc(deviceId) // .doc(deviceId)
.collection('mcbLinks') // .collection('mcbLinks')
.doc(i.toString()) // .doc(i.toString())
.collection('Timers') // .collection('Timers')
.doc(); // .doc();
batch.set(mcbLinkTimerRef, timer); // batch.set(mcbLinkTimerRef, timer);
} // }
batch.set(mcbLinksRef, mcbLinks); batch.set(mcbLinksRef, mcbLinks);
} }
...@@ -130,7 +130,7 @@ const main = { ...@@ -130,7 +130,7 @@ const main = {
const initTime = new Date(); const initTime = new Date();
initTime.setFullYear(2019); initTime.setFullYear(2019);
initTime.setMonth(1); initTime.setMonth(0);
initTime.setDate(0); initTime.setDate(0);
initTime.setSeconds(0); initTime.setSeconds(0);
......
...@@ -230,6 +230,9 @@ const MainStack = createStackNavigator( ...@@ -230,6 +230,9 @@ const MainStack = createStackNavigator(
}, },
{ {
defaultNavigationOptions: { header: null }, defaultNavigationOptions: { header: null },
tabBarOptions: {
keyboardHidesTabBar: true,
},
} }
); );
...@@ -245,6 +248,9 @@ const IntroStack = createStackNavigator( ...@@ -245,6 +248,9 @@ const IntroStack = createStackNavigator(
{ {
initialRouteName: 'Login', initialRouteName: 'Login',
defaultNavigationOptions: { headerStyle: { borderColor: 'transparent', elevation: 0, borderBottomWidth: 0 } }, defaultNavigationOptions: { headerStyle: { borderColor: 'transparent', elevation: 0, borderBottomWidth: 0 } },
tabBarOptions: {
keyboardHidesTabBar: true,
},
} }
); );
...@@ -256,6 +262,9 @@ const AppStack = createSwitchNavigator( ...@@ -256,6 +262,9 @@ const AppStack = createSwitchNavigator(
}, },
{ {
initialRouteName: 'AuthLoading', //default AuthLoading initialRouteName: 'AuthLoading', //default AuthLoading
tabBarOptions: {
keyboardHidesTabBar: true,
},
} }
); );
......
...@@ -186,6 +186,7 @@ android { ...@@ -186,6 +186,7 @@ android {
pickFirst '**/x86/libjsc.so' pickFirst '**/x86/libjsc.so'
pickFirst '**/armeabi-v7a/libjsc.so' pickFirst '**/armeabi-v7a/libjsc.so'
} }
buildToolsVersion = buildToolsVersion
} }
dependencies { dependencies {
......
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
\ No newline at end of file
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateAlwaysHidden" android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
...@@ -2,7 +2,6 @@ rootProject.name = 'rn_safetcutapp' ...@@ -2,7 +2,6 @@ rootProject.name = 'rn_safetcutapp'
include ':react-native-svg' include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android') project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
include ':react-native-camera' include ':react-native-camera'
project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android')
include ':app'
...@@ -7,13 +7,20 @@ import Swipeable from 'react-native-gesture-handler/Swipeable'; ...@@ -7,13 +7,20 @@ import Swipeable from 'react-native-gesture-handler/Swipeable';
import IconMaterialIcons from 'react-native-vector-icons/MaterialIcons'; import IconMaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { Overlay } from 'react-native-elements'; import { Overlay } from 'react-native-elements';
import { format } from 'date-fns'; import { format } from 'date-fns';
import { connect } from 'react-redux';
import { getSelectedTimerData, setEditModalVisible, deleteTimer, getTimers } from '../reduxStore/actions/timersAction';
const AnimatedIcon = Animated.createAnimatedComponent(IconMaterialIcons); const AnimatedIcon = Animated.createAnimatedComponent(IconMaterialIcons);
const Row = ({ data }) => { const Row = ({ data, getSelectedTimerData, setEditModalVisible }) => {
// console.log(data);
return ( return (
<RectButton style={styles.rectButton} onPress={() => alert('hello ' + data.name)}> <RectButton
style={styles.rectButton}
onPress={() => {
getSelectedTimerData(data);
setEditModalVisible(true);
}}
>
<View style={{ flexDirection: 'row', paddingVertical: 5 }}> <View style={{ flexDirection: 'row', paddingVertical: 5 }}>
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
<View style={{ flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between' }}> <View style={{ flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between' }}>
...@@ -71,8 +78,8 @@ const Row = ({ data }) => { ...@@ -71,8 +78,8 @@ const Row = ({ data }) => {
{data.type === 'main' {data.type === 'main'
? 'Main' ? 'Main'
: data.type === 'mcbLink' : data.type === 'mcbLink'
? `MCB LINK${data.id}` ? `MCB LINK${data.mcbLinkId}`
: `MCB Link${data.mcbLinkId} | Sub Breaker${data.id}`} : `MCB Link ${data.mcbLinkId} | Sub Breaker ${data.subBreakerId}`}
</Text> </Text>
</View> </View>
<View style={{ flex: 1, alignItems: 'flex-end' }}> <View style={{ flex: 1, alignItems: 'flex-end' }}>
...@@ -101,13 +108,43 @@ const Row = ({ data }) => { ...@@ -101,13 +108,43 @@ const Row = ({ data }) => {
); );
}; };
const mapDispatchToProps = {
getSelectedTimerData,
setEditModalVisible,
};
const WarppedRow = connect(
null,
mapDispatchToProps
)(Row);
class SwipeableRow extends Component { class SwipeableRow extends Component {
selectedRow = null;
state = { state = {
isVisible: false, isVisible: false,
}; };
renderRightActions = (progress, dragX) => { updateRef = instance => {
this.swipeInstance = instance;
};
showConfirmDelete = () => {
this.swipeInstance.close();
this.setState({ isVisible: true });
};
cancel = () => {
this.setState({ isVisible: false });
};
delete = data => {
console.log(data);
this.props.deleteTimer(data);
this.props.getTimers();
this.setState({ isVisible: false });
};
_onSwipeOpen = () => {
this.props.onSwipeOpen(this.swipeInstance);
};
renderRightActions = (progress, dragX) => data => {
const scale = dragX.interpolate({ const scale = dragX.interpolate({
inputRange: [-80, 0], inputRange: [-80, 0],
outputRange: [1, 0], outputRange: [1, 0],
...@@ -115,7 +152,7 @@ class SwipeableRow extends Component { ...@@ -115,7 +152,7 @@ class SwipeableRow extends Component {
}); });
return ( return (
<> <>
<RectButton style={styles.rightAction} onPress={this.cfDelete}> <RectButton style={styles.rightAction} onPress={this.showConfirmDelete}>
<AnimatedIcon <AnimatedIcon
name="delete-forever" name="delete-forever"
size={30} size={30}
...@@ -139,7 +176,7 @@ class SwipeableRow extends Component { ...@@ -139,7 +176,7 @@ class SwipeableRow extends Component {
<Button transparent style={{ width: '40%' }} onPress={this.cancel} rounded> <Button transparent style={{ width: '40%' }} onPress={this.cancel} rounded>
<Text style={{ color: color.grey }}>Cancel</Text> <Text style={{ color: color.grey }}>Cancel</Text>
</Button> </Button>
<Button style={styles.delBtn} onPress={this.delete} rounded> <Button style={styles.delBtn} onPress={() => this.delete(data)} rounded>
<Text>Delete</Text> <Text>Delete</Text>
</Button> </Button>
</View> </View>
...@@ -148,23 +185,6 @@ class SwipeableRow extends Component { ...@@ -148,23 +185,6 @@ class SwipeableRow extends Component {
</> </>
); );
}; };
updateRef = instance => {
this.swipeInstance = instance;
};
cfDelete = () => {
this.swipeInstance.close();
this.setState({ isVisible: true });
};
cancel = () => {
this.setState({ isVisible: false });
};
delete = () => {
this.setState({ isVisible: false });
};
_onSwipeOpen = () => {
this.props.onSwipeOpen(this.swipeInstance);
};
render() { render() {
return ( return (
...@@ -172,17 +192,25 @@ class SwipeableRow extends Component { ...@@ -172,17 +192,25 @@ class SwipeableRow extends Component {
ref={this.updateRef} ref={this.updateRef}
friction={2} friction={2}
rightThreshold={40} rightThreshold={40}
renderRightActions={this.renderRightActions} renderRightActions={(progress, dragX) => this.renderRightActions(progress, dragX)(this.props.item)}
containerStyle={{ backgroundColor: color.primary }} containerStyle={{ backgroundColor: color.primary }}
onSwipeableWillOpen={this._onSwipeOpen} onSwipeableWillOpen={this._onSwipeOpen}
> >
<Row data={this.props.item} index={this.props.index} /> <WarppedRow data={this.props.item} index={this.props.index} />
</Swipeable> </Swipeable>
); );
} }
} }
export default SwipeableRow; const _mapDispatchToProps = {
deleteTimer,
getTimers,
};
export default connect(
null,
_mapDispatchToProps
)(SwipeableRow);
const styles = StyleSheet.create({ const styles = StyleSheet.create({
leftAction: { leftAction: {
......
...@@ -15,4 +15,5 @@ const app = firebase.initializeApp({ ...@@ -15,4 +15,5 @@ const app = firebase.initializeApp({
export default app; export default app;
const fireStore = app.firestore(); const fireStore = app.firestore();
export { fireStore }; export { fireStore };
...@@ -7,13 +7,11 @@ export const GET_TIMERS_ERROR = 'GET_TIMERS_ERROR'; ...@@ -7,13 +7,11 @@ export const GET_TIMERS_ERROR = 'GET_TIMERS_ERROR';
export const GET_EXISTED_DATA = 'GET_EXISTED_DATA'; export const GET_EXISTED_DATA = 'GET_EXISTED_DATA';
export const GET_MAIN_DEVICE_TIMERS = 'GET_MAIN_DEVICE_TIMERS'; export const GET_MAIN_DEVICE_TIMERS = 'GET_MAIN_DEVICE_TIMERS';
export const GET_MCBLINKS_TIMERS = 'GET_MCBLINKS_TIMERS'; // export const GET_MCBLINKS_TIMERS = 'GET_MCBLINKS_TIMERS';
export const GET_SUBBREAKERS_TIMERS = 'GET_SUBBREAKERS_TIMERS'; export const GET_SUBBREAKERS_TIMERS = 'GET_SUBBREAKERS_TIMERS';
// export const getTimersAction = (mainDeviceTimers, mcbLinksTimers, subBreakersTimers) => ({ export const GET_SELECTED_TIMER_DATA = 'GET_SELECTED_TIMER_DATA';
// type: GET_TIMERS, export const SET_EDIT_MODAL_VISIBLE = 'SET_EDIT_MODAL_VISIBLE';
// allTimers: { mainDeviceTimers, mcbLinksTimers, subBreakersTimers },
// });
export const getTimersAction = allTimers => ({ export const getTimersAction = allTimers => ({
type: GET_TIMERS, type: GET_TIMERS,
...@@ -25,10 +23,10 @@ export const getMainDeviceTImersAction = mainDeviceTimers => ({ ...@@ -25,10 +23,10 @@ export const getMainDeviceTImersAction = mainDeviceTimers => ({
mainDeviceTimers, mainDeviceTimers,
}); });
export const getMcbLinksTimersAction = mcbLinksTimers => ({ // export const getMcbLinksTimersAction = mcbLinksTimers => ({
type: GET_MCBLINKS_TIMERS, // type: GET_MCBLINKS_TIMERS,
mcbLinksTimers, // mcbLinksTimers,
}); // });
export const getSubBreakersTimersAction = subBreakersTimers => ({ export const getSubBreakersTimersAction = subBreakersTimers => ({
type: GET_SUBBREAKERS_TIMERS, type: GET_SUBBREAKERS_TIMERS,
...@@ -40,6 +38,16 @@ export const getExistedDataAction = existedData => ({ ...@@ -40,6 +38,16 @@ export const getExistedDataAction = existedData => ({
existedData, existedData,
}); });
export const getSelectedTimerDataAction = selectedTimerData => ({
type: GET_SELECTED_TIMER_DATA,
selectedTimerData,
});
export const setEditModalVisibleAction = bool => ({
type: SET_EDIT_MODAL_VISIBLE,
isEditVisible: bool,
});
export const loadingAction = bool => ({ export const loadingAction = bool => ({
type: GET_TIMERS_LOADING, type: GET_TIMERS_LOADING,
isLoading: bool, isLoading: bool,
...@@ -57,12 +65,11 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -57,12 +65,11 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(loadingAction(true)); dispatch(loadingAction(true));
let allTimersData = []; let allTimersData = [];
let mainDeviceTimers = []; let mainDeviceTimers = [];
let mcbLinksTimers = [];
let subBreakersTimers = []; let subBreakersTimers = [];
// let existedMcbLinks = [];
let existedSubBreakers = []; let existedSubBreakers = [];
let mcbLinksSubBreakersTimers = [];
//main device section //main device section
/*-------------------------------------*/ /*-------------------------------------*/
...@@ -80,19 +87,17 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -80,19 +87,17 @@ export const getTimers = () => async (dispatch, getState) => {
const selectedDeviceDetailsData = selectedDeviceDetails.data(); const selectedDeviceDetailsData = selectedDeviceDetails.data();
await Promise.all( selectedDeviceTimers.docs.map(timer => {
selectedDeviceTimers.docs.map(timer => { if (timer.exists) {
if (timer.exists) { mainDeviceTimers.push(
mainDeviceTimers.push( Object.assign(timer.data(), {
Object.assign(timer.data(), { key: timer.id,
id: timer.id, type: selectedDeviceDetailsData.type,
type: selectedDeviceDetailsData.type, name: selectedDeviceDetailsData.name,
name: selectedDeviceDetailsData.name, })
}) );
); }
} });
})
);
//mcblink section //mcblink section
/*-------------------------------------*/ /*-------------------------------------*/
...@@ -106,33 +111,8 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -106,33 +111,8 @@ export const getTimers = () => async (dispatch, getState) => {
await Promise.all( await Promise.all(
selectedDeviceMcbLinksDetails.docs.map(async mcbLink => { selectedDeviceMcbLinksDetails.docs.map(async mcbLink => {
if (mcbLink.exists) { if (mcbLink.exists) {
// existedMcbLinks.push(Object.assign(mcbLink.data(), { id: mcbLink.id }));
let mcbLinkTimers = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id)
.collection('Timers')
.orderBy('timer', 'asc')
.get();
mcbLinkTimers.docs.map(mcbLinkTimer => {
if (mcbLinkTimer.exists) {
mcbLinksTimers.push(
Object.assign(mcbLinkTimer.data(), {
id: mcbLink.id,
key: mcbLinkTimer.id,
type: mcbLink.data().type,
name: mcbLink.data().name,
})
);
}
});
//subbreaker section //subbreaker section
/*-------------------------------------*/ /*-------------------------------------*/
const selectedDeviceSubBreakersDetails = await fireStore const selectedDeviceSubBreakersDetails = await fireStore
.collection('device') .collection('device')
.doc(selectedDeviceId) .doc(selectedDeviceId)
...@@ -143,7 +123,7 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -143,7 +123,7 @@ export const getTimers = () => async (dispatch, getState) => {
existedSubBreakers.push( existedSubBreakers.push(
selectedDeviceSubBreakersDetails.docs.map(subBreaker => selectedDeviceSubBreakersDetails.docs.map(subBreaker =>
Object.assign(subBreaker.data(), { mcbLinkId: mcbLink.id, id: subBreaker.id }) Object.assign(subBreaker.data(), { mcbLinkId: mcbLink.id, subBreakerId: subBreaker.id })
) )
); );
...@@ -166,7 +146,7 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -166,7 +146,7 @@ export const getTimers = () => async (dispatch, getState) => {
subBreakersTimers.push( subBreakersTimers.push(
Object.assign(subBreakerTimer.data(), { Object.assign(subBreakerTimer.data(), {
mcbLinkId: mcbLink.id, mcbLinkId: mcbLink.id,
id: subBreaker.id, subBreakerId: subBreaker.id,
key: subBreakerTimer.id, key: subBreakerTimer.id,
type: subBreaker.data().type, type: subBreaker.data().type,
name: subBreaker.data().name, name: subBreaker.data().name,
...@@ -184,10 +164,9 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -184,10 +164,9 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(getExistedDataAction(existedSubBreakers)); dispatch(getExistedDataAction(existedSubBreakers));
dispatch(getMainDeviceTImersAction(mainDeviceTimers)); dispatch(getMainDeviceTImersAction(mainDeviceTimers));
dispatch(getMcbLinksTimersAction(mcbLinksTimers));
dispatch(getSubBreakersTimersAction(subBreakersTimers)); dispatch(getSubBreakersTimersAction(subBreakersTimers));
allTimersData = [...mainDeviceTimers, ...mcbLinksTimers, ...subBreakersTimers]; allTimersData = [...mainDeviceTimers, ...subBreakersTimers];
dispatch(getTimersAction(allTimersData)); dispatch(getTimersAction(allTimersData));
} catch (error) { } catch (error) {
dispatch(errorAction(error.message || error || 'Error')); dispatch(errorAction(error.message || error || 'Error'));
...@@ -195,6 +174,116 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -195,6 +174,116 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(loadingAction(false)); dispatch(loadingAction(false));
}; };
export const getSelectedTimerData = data => async dispatch => {
await dispatch(getSelectedTimerDataAction(data));
};
export const setEditModalVisible = bool => async dispatch => {
await dispatch(setEditModalVisibleAction(bool));
};
export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { selectedDeviceId } = currentSelectedDeviceReducer;
let docRef = null;
try {
// dispatch(loadingAction(true));
if (mcbLinkId && subBreakerId) {
docRef = fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLinkId.toString())
.collection('subBreakers')
.doc(subBreakerId.toString())
.collection('Timers');
} else {
docRef = fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('Timers');
}
let timers = await docRef.get();
// console.log('timerLength', timers.size, timers.docs.length);
if (timers.size < 5) {
await docRef.add(settingTime);
return true;
} else {
alert('This Breaker cannot have more than 5 timers.');
return false;
}
} catch (e) {
alert(e);
}
};
export const editTimer = settingTime => async (dispatch, getState) => {
const { currentSelectedDeviceReducer, timersReducer } = getState();
const {
selectedTimerData: { mcbLinkId, subBreakerId, key },
} = timersReducer;
const { selectedDeviceId } = currentSelectedDeviceReducer;
let docRef = null;
try {
// dispatch(loadingAction(true));
if (mcbLinkId && subBreakerId) {
docRef = fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLinkId)
.collection('subBreakers')
.doc(subBreakerId)
.collection('Timers')
.doc(key);
} else {
docRef = fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('Timers')
.doc(key);
}
await docRef.update(settingTime);
} catch (e) {
alert(e);
}
};
export const deleteTimer = selectedData => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { selectedDeviceId } = currentSelectedDeviceReducer;
const { mcbLinkId, subBreakerId, key } = selectedData;
let docRef = null;
try {
// dispatch(loadingAction(true));
if (key) {
if (mcbLinkId && subBreakerId) {
docRef = fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLinkId)
.collection('subBreakers')
.doc(subBreakerId)
.collection('Timers')
.doc(key);
} else {
docRef = fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('Timers')
.doc(key);
}
await docRef.delete();
}
} catch (e) {
alert(e);
}
};
// export const getTimers = () => async (dispatch, getState) => { // export const getTimers = () => async (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState(); // const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer; // const { selectedDeviceId } = currentSelectedDeviceReducer;
......
...@@ -4,18 +4,22 @@ import { ...@@ -4,18 +4,22 @@ import {
GET_TIMERS_ERROR, GET_TIMERS_ERROR,
GET_EXISTED_DATA, GET_EXISTED_DATA,
GET_MAIN_DEVICE_TIMERS, GET_MAIN_DEVICE_TIMERS,
GET_MCBLINKS_TIMERS,
GET_SUBBREAKERS_TIMERS, GET_SUBBREAKERS_TIMERS,
GET_SELECTED_TIMER_DATA,
SET_EDIT_MODAL_VISIBLE,
// GET_MCBLINKS_TIMERS,
} from '../actions/timersAction'; } from '../actions/timersAction';
const initState = { const initState = {
allTimers: [], allTimers: [],
mainDeviceTimers: [], mainDeviceTimers: [],
mcbLinksTimers: [],
subBreakersTimers: [], subBreakersTimers: [],
existedData: {}, existedData: {},
selectedTimerData: null,
isEditVisible: false,
isLoading: true, isLoading: true,
error: null, error: null,
// mcbLinksTimers: [],
}; };
const timersReducer = (state = initState, action) => { const timersReducer = (state = initState, action) => {
...@@ -26,14 +30,18 @@ const timersReducer = (state = initState, action) => { ...@@ -26,14 +30,18 @@ const timersReducer = (state = initState, action) => {
return { ...state, allTimers: action.allTimers }; return { ...state, allTimers: action.allTimers };
case GET_MAIN_DEVICE_TIMERS: case GET_MAIN_DEVICE_TIMERS:
return { ...state, mainDeviceTimers: action.mainDeviceTimers }; return { ...state, mainDeviceTimers: action.mainDeviceTimers };
case GET_MCBLINKS_TIMERS:
return { ...state, mcbLinksTimers: action.mcbLinksTimers };
case GET_SUBBREAKERS_TIMERS: case GET_SUBBREAKERS_TIMERS:
return { ...state, subBreakersTimers: action.subBreakersTimers }; return { ...state, subBreakersTimers: action.subBreakersTimers };
case GET_SELECTED_TIMER_DATA:
return { ...state, selectedTimerData: action.selectedTimerData };
case SET_EDIT_MODAL_VISIBLE:
return { ...state, isEditVisible: action.isEditVisible };
case GET_TIMERS_LOADING: case GET_TIMERS_LOADING:
return { ...state, isLoading: action.isLoading }; return { ...state, isLoading: action.isLoading };
case GET_TIMERS_ERROR: case GET_TIMERS_ERROR:
return { ...state, error: action.error }; return { ...state, error: action.error };
// case GET_MCBLINKS_TIMERS:
// return { ...state, mcbLinksTimers: action.mcbLinksTimers };
default: default:
return state; return state;
} }
......
...@@ -36,7 +36,7 @@ class SmartMeterScreen extends PureComponent { ...@@ -36,7 +36,7 @@ class SmartMeterScreen extends PureComponent {
componentDidMount = () => { componentDidMount = () => {
this._isMounted = true; this._isMounted = true;
// this.getData(); this.getData();
}; };
renderItem = ({ item, index }) => { renderItem = ({ item, index }) => {
...@@ -49,7 +49,6 @@ class SmartMeterScreen extends PureComponent { ...@@ -49,7 +49,6 @@ class SmartMeterScreen extends PureComponent {
isOn={item.switch || false} isOn={item.switch || false}
onPressEachCard={async () => { onPressEachCard={async () => {
await this.props.setCurrentSelected(item.deviceId); await this.props.setCurrentSelected(item.deviceId);
await this.props.getTimers();
this.props.navigation.navigate('SmartMeterDetail', { name: item.name || '' }); this.props.navigation.navigate('SmartMeterDetail', { name: item.name || '' });
}} }}
/> />
...@@ -155,7 +154,6 @@ const mapStateToProps = state => ({ ...@@ -155,7 +154,6 @@ const mapStateToProps = state => ({
const mapDispatchToProps = { const mapDispatchToProps = {
getAllMainDeviceInfo, getAllMainDeviceInfo,
setCurrentSelected, setCurrentSelected,
getTimers,
}; };
export default connect( export default connect(
......
...@@ -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 { getAllMainDeviceInfo } from '../../reduxStore/actions/allMainDeviceAction'; // import { getAllMainDeviceInfo } from '../../reduxStore/actions/allMainDeviceAction';
class AuthLoadingScreen extends Component { class AuthLoadingScreen extends Component {
static navigationOptions = { static navigationOptions = {
...@@ -33,15 +33,19 @@ class AuthLoadingScreen extends Component { ...@@ -33,15 +33,19 @@ class AuthLoadingScreen extends Component {
const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched'); const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched');
const RememberedLogin = await AsyncStorage.getItem('RememberedLogin'); const RememberedLogin = await AsyncStorage.getItem('RememberedLogin');
app.auth().onAuthStateChanged(async user => { try {
if (user) { app.auth().onAuthStateChanged(async user => {
await this.props.getCurrentUser(user); if (user) {
await this.props.getAllMainDeviceInfo(); await this.props.getCurrentUser(user);
this.props.navigation.navigate(RememberedLogin === 'true' ? 'Main' : 'Login'); // await this.props.getAllMainDeviceInfo();
} else { this.props.navigation.navigate(RememberedLogin === 'true' ? 'Main' : 'Login');
this.props.navigation.navigate(alreadyLaunched === 'true' ? 'Login' : 'Onboarding'); } else {
} this.props.navigation.navigate(alreadyLaunched === 'true' ? 'Login' : 'Onboarding');
}); }
});
} catch (e) {
alert(e);
}
}; };
componentDidMount = async () => { componentDidMount = async () => {
...@@ -67,16 +71,16 @@ class AuthLoadingScreen extends Component { ...@@ -67,16 +71,16 @@ class AuthLoadingScreen extends Component {
} }
} }
mapStateToProps = state => ({ // mapStateToProps = state => ({
uid: state.currentUserReducer.uid, // uid: state.currentUserReducer.uid,
}); // });
const mapDispatchToProps = { const mapDispatchToProps = {
getCurrentUser, getCurrentUser,
getAllMainDeviceInfo, // getAllMainDeviceInfo,
}; };
export default connect( export default connect(
mapStateToProps, null,
mapDispatchToProps mapDispatchToProps
)(AuthLoadingScreen); )(AuthLoadingScreen);
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