Commit 4a7df4f1 by HaOuiha

update timerscreen

parent bf660d6c
......@@ -44,15 +44,15 @@ const createMockData = () => {
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();
for (let i = 1; i <= 2; i++) {
let mainTimerRef = fireStore
.collection('device')
.doc(deviceId)
.collection('Timers')
.doc();
// batch.set(mainTimerRef, timer);
// }
batch.set(mainTimerRef, timer);
}
/*------------------------------*/
for (let i = 1; i <= 4; i++) {
const mcbLinks = {
......@@ -66,17 +66,17 @@ const createMockData = () => {
.collection('mcbLinks')
.doc(i.toString());
for (let z = 1; z <= 1; z++) {
let mcbLinkTimerRef = fireStore
.collection('device')
.doc(deviceId)
.collection('mcbLinks')
.doc(i.toString())
.collection('Timers')
.doc();
// for (let z = 1; z <= 1; z++) {
// let mcbLinkTimerRef = fireStore
// .collection('device')
// .doc(deviceId)
// .collection('mcbLinks')
// .doc(i.toString())
// .collection('Timers')
// .doc();
batch.set(mcbLinkTimerRef, timer);
}
// batch.set(mcbLinkTimerRef, timer);
// }
batch.set(mcbLinksRef, mcbLinks);
}
......@@ -130,7 +130,7 @@ const main = {
const initTime = new Date();
initTime.setFullYear(2019);
initTime.setMonth(1);
initTime.setMonth(0);
initTime.setDate(0);
initTime.setSeconds(0);
......
......@@ -238,6 +238,9 @@ const MainStack = createStackNavigator(
},
{
defaultNavigationOptions: { header: null },
tabBarOptions: {
keyboardHidesTabBar: true,
},
}
);
......@@ -253,6 +256,9 @@ const IntroStack = createStackNavigator(
{
initialRouteName: 'Login',
defaultNavigationOptions: { headerStyle: { borderColor: 'transparent', elevation: 0, borderBottomWidth: 0 } },
tabBarOptions: {
keyboardHidesTabBar: true,
},
}
);
......@@ -264,6 +270,9 @@ const AppStack = createSwitchNavigator(
},
{
initialRouteName: 'AuthLoading', //default AuthLoading
tabBarOptions: {
keyboardHidesTabBar: true,
},
}
);
......
......@@ -186,6 +186,7 @@ android {
pickFirst '**/x86/libjsc.so'
pickFirst '**/armeabi-v7a/libjsc.so'
}
buildToolsVersion = buildToolsVersion
}
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 @@
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="stateAlwaysHidden"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
rootProject.name = 'rn_safetcutapp'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
include ':react-native-camera'
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';
import IconMaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { Overlay } from 'react-native-elements';
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 Row = ({ data }) => {
// console.log(data);
const Row = ({ data, getSelectedTimerData, setEditModalVisible }) => {
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={{ flex: 1 }}>
<View style={{ flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'space-between' }}>
......@@ -71,8 +78,8 @@ const Row = ({ data }) => {
{data.type === 'main'
? 'Main'
: data.type === 'mcbLink'
? `MCB LINK${data.id}`
: `MCB Link${data.mcbLinkId} | Sub Breaker${data.id}`}
? `MCB LINK${data.mcbLinkId}`
: `MCB Link ${data.mcbLinkId} | Sub Breaker ${data.subBreakerId}`}
</Text>
</View>
<View style={{ flex: 1, alignItems: 'flex-end' }}>
......@@ -101,13 +108,43 @@ const Row = ({ data }) => {
);
};
const mapDispatchToProps = {
getSelectedTimerData,
setEditModalVisible,
};
const WarppedRow = connect(
null,
mapDispatchToProps
)(Row);
class SwipeableRow extends Component {
selectedRow = null;
state = {
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({
inputRange: [-80, 0],
outputRange: [1, 0],
......@@ -115,7 +152,7 @@ class SwipeableRow extends Component {
});
return (
<>
<RectButton style={styles.rightAction} onPress={this.cfDelete}>
<RectButton style={styles.rightAction} onPress={this.showConfirmDelete}>
<AnimatedIcon
name="delete-forever"
size={30}
......@@ -139,7 +176,7 @@ class SwipeableRow extends Component {
<Button transparent style={{ width: '40%' }} onPress={this.cancel} rounded>
<Text style={{ color: color.grey }}>Cancel</Text>
</Button>
<Button style={styles.delBtn} onPress={this.delete} rounded>
<Button style={styles.delBtn} onPress={() => this.delete(data)} rounded>
<Text>Delete</Text>
</Button>
</View>
......@@ -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() {
return (
......@@ -172,17 +192,25 @@ class SwipeableRow extends Component {
ref={this.updateRef}
friction={2}
rightThreshold={40}
renderRightActions={this.renderRightActions}
renderRightActions={(progress, dragX) => this.renderRightActions(progress, dragX)(this.props.item)}
containerStyle={{ backgroundColor: color.primary }}
onSwipeableWillOpen={this._onSwipeOpen}
>
<Row data={this.props.item} index={this.props.index} />
<WarppedRow data={this.props.item} index={this.props.index} />
</Swipeable>
);
}
}
export default SwipeableRow;
const _mapDispatchToProps = {
deleteTimer,
getTimers,
};
export default connect(
null,
_mapDispatchToProps
)(SwipeableRow);
const styles = StyleSheet.create({
leftAction: {
......
......@@ -15,4 +15,5 @@ const app = firebase.initializeApp({
export default app;
const fireStore = app.firestore();
export { fireStore };
......@@ -7,13 +7,11 @@ export const GET_TIMERS_ERROR = 'GET_TIMERS_ERROR';
export const GET_EXISTED_DATA = 'GET_EXISTED_DATA';
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 getTimersAction = (mainDeviceTimers, mcbLinksTimers, subBreakersTimers) => ({
// type: GET_TIMERS,
// allTimers: { mainDeviceTimers, mcbLinksTimers, subBreakersTimers },
// });
export const GET_SELECTED_TIMER_DATA = 'GET_SELECTED_TIMER_DATA';
export const SET_EDIT_MODAL_VISIBLE = 'SET_EDIT_MODAL_VISIBLE';
export const getTimersAction = allTimers => ({
type: GET_TIMERS,
......@@ -25,10 +23,10 @@ export const getMainDeviceTImersAction = mainDeviceTimers => ({
mainDeviceTimers,
});
export const getMcbLinksTimersAction = mcbLinksTimers => ({
type: GET_MCBLINKS_TIMERS,
mcbLinksTimers,
});
// export const getMcbLinksTimersAction = mcbLinksTimers => ({
// type: GET_MCBLINKS_TIMERS,
// mcbLinksTimers,
// });
export const getSubBreakersTimersAction = subBreakersTimers => ({
type: GET_SUBBREAKERS_TIMERS,
......@@ -40,6 +38,16 @@ export const getExistedDataAction = 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 => ({
type: GET_TIMERS_LOADING,
isLoading: bool,
......@@ -57,12 +65,11 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(loadingAction(true));
let allTimersData = [];
let mainDeviceTimers = [];
let mcbLinksTimers = [];
let subBreakersTimers = [];
// let existedMcbLinks = [];
let existedSubBreakers = [];
let mcbLinksSubBreakersTimers = [];
//main device section
/*-------------------------------------*/
......@@ -80,19 +87,17 @@ export const getTimers = () => async (dispatch, getState) => {
const selectedDeviceDetailsData = selectedDeviceDetails.data();
await Promise.all(
selectedDeviceTimers.docs.map(timer => {
if (timer.exists) {
mainDeviceTimers.push(
Object.assign(timer.data(), {
id: timer.id,
key: timer.id,
type: selectedDeviceDetailsData.type,
name: selectedDeviceDetailsData.name,
})
);
}
})
);
});
//mcblink section
/*-------------------------------------*/
......@@ -106,33 +111,8 @@ export const getTimers = () => async (dispatch, getState) => {
await Promise.all(
selectedDeviceMcbLinksDetails.docs.map(async mcbLink => {
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
/*-------------------------------------*/
const selectedDeviceSubBreakersDetails = await fireStore
.collection('device')
.doc(selectedDeviceId)
......@@ -143,7 +123,7 @@ export const getTimers = () => async (dispatch, getState) => {
existedSubBreakers.push(
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) => {
subBreakersTimers.push(
Object.assign(subBreakerTimer.data(), {
mcbLinkId: mcbLink.id,
id: subBreaker.id,
subBreakerId: subBreaker.id,
key: subBreakerTimer.id,
type: subBreaker.data().type,
name: subBreaker.data().name,
......@@ -184,10 +164,9 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch(getExistedDataAction(existedSubBreakers));
dispatch(getMainDeviceTImersAction(mainDeviceTimers));
dispatch(getMcbLinksTimersAction(mcbLinksTimers));
dispatch(getSubBreakersTimersAction(subBreakersTimers));
allTimersData = [...mainDeviceTimers, ...mcbLinksTimers, ...subBreakersTimers];
allTimersData = [...mainDeviceTimers, ...subBreakersTimers];
dispatch(getTimersAction(allTimersData));
} catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
......@@ -195,6 +174,116 @@ export const getTimers = () => async (dispatch, getState) => {
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) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
......
......@@ -4,18 +4,22 @@ import {
GET_TIMERS_ERROR,
GET_EXISTED_DATA,
GET_MAIN_DEVICE_TIMERS,
GET_MCBLINKS_TIMERS,
GET_SUBBREAKERS_TIMERS,
GET_SELECTED_TIMER_DATA,
SET_EDIT_MODAL_VISIBLE,
// GET_MCBLINKS_TIMERS,
} from '../actions/timersAction';
const initState = {
allTimers: [],
mainDeviceTimers: [],
mcbLinksTimers: [],
subBreakersTimers: [],
existedData: {},
selectedTimerData: null,
isEditVisible: false,
isLoading: true,
error: null,
// mcbLinksTimers: [],
};
const timersReducer = (state = initState, action) => {
......@@ -26,14 +30,18 @@ const timersReducer = (state = initState, action) => {
return { ...state, allTimers: action.allTimers };
case GET_MAIN_DEVICE_TIMERS:
return { ...state, mainDeviceTimers: action.mainDeviceTimers };
case GET_MCBLINKS_TIMERS:
return { ...state, mcbLinksTimers: action.mcbLinksTimers };
case GET_SUBBREAKERS_TIMERS:
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:
return { ...state, isLoading: action.isLoading };
case GET_TIMERS_ERROR:
return { ...state, error: action.error };
// case GET_MCBLINKS_TIMERS:
// return { ...state, mcbLinksTimers: action.mcbLinksTimers };
default:
return state;
}
......
......@@ -9,7 +9,6 @@ import { isIphoneX } from '../../../utils/isPhoneX';
import { getAllMainDeviceInfo } from '../../../reduxStore/actions/allMainDeviceAction';
import { setCurrentSelected } from '../../../reduxStore/actions/currentSelectedAction';
import { connect } from 'react-redux';
import { getTimers } from '../../../reduxStore/actions/timersAction';
class SmartMeterScreen extends PureComponent {
static navigationOptions = ({ navigation }) => ({
......@@ -34,7 +33,7 @@ class SmartMeterScreen extends PureComponent {
componentDidMount = () => {
this._isMounted = true;
// this.getData();
this.getData();
};
renderItem = ({ item, index }) => {
......@@ -47,7 +46,6 @@ class SmartMeterScreen extends PureComponent {
isOn={item.isOn || false}
onPressEachCard={async () => {
await this.props.setCurrentSelected(item.deviceId);
await this.props.getTimers();
this.props.navigation.navigate('SmartMeterDetail', { name: item.name || '' });
}}
/>
......@@ -64,7 +62,7 @@ class SmartMeterScreen extends PureComponent {
return !error ? (
<FlatList
removeClippedSubviews={true}
removeClippedSubviews={false}
refreshing={isLoading}
onRefresh={this.getData}
style={[theme.container, theme.containerWithPadding]}
......@@ -101,7 +99,6 @@ const mapStateToProps = state => ({
const mapDispatchToProps = {
getAllMainDeviceInfo,
setCurrentSelected,
getTimers,
};
export default connect(
......
......@@ -6,7 +6,7 @@ import { width } from '../../constants/Layout';
import app from '../../firebase';
import { connect } from 'react-redux';
import { getCurrentUser } from '../../reduxStore/actions/cerrentUserAction';
import { getAllMainDeviceInfo } from '../../reduxStore/actions/allMainDeviceAction';
// import { getAllMainDeviceInfo } from '../../reduxStore/actions/allMainDeviceAction';
class AuthLoadingScreen extends Component {
static navigationOptions = {
......@@ -33,15 +33,19 @@ class AuthLoadingScreen extends Component {
const alreadyLaunched = await AsyncStorage.getItem('alreadyLaunched');
const RememberedLogin = await AsyncStorage.getItem('RememberedLogin');
try {
app.auth().onAuthStateChanged(async user => {
if (user) {
await this.props.getCurrentUser(user);
await this.props.getAllMainDeviceInfo();
// await this.props.getAllMainDeviceInfo();
this.props.navigation.navigate(RememberedLogin === 'true' ? 'Main' : 'Login');
} else {
this.props.navigation.navigate(alreadyLaunched === 'true' ? 'Login' : 'Onboarding');
}
});
} catch (e) {
alert(e);
}
};
componentDidMount = async () => {
......@@ -67,16 +71,16 @@ class AuthLoadingScreen extends Component {
}
}
mapStateToProps = state => ({
uid: state.currentUserReducer.uid,
});
// mapStateToProps = state => ({
// uid: state.currentUserReducer.uid,
// });
const mapDispatchToProps = {
getCurrentUser,
getAllMainDeviceInfo,
// getAllMainDeviceInfo,
};
export default connect(
mapStateToProps,
null,
mapDispatchToProps
)(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