Commit 701dd903 by HaOuiha

update

parent a3e7d977
...@@ -19,6 +19,7 @@ console.disableYellowBox = true; ...@@ -19,6 +19,7 @@ console.disableYellowBox = true;
const Application = () => { const Application = () => {
useEffect(() => { useEffect(() => {
fixTimerWarning(); fixTimerWarning();
// createMockData();
}, []); }, []);
return ( return (
...@@ -43,15 +44,15 @@ const createMockData = () => { ...@@ -43,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 <= 5; 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 = {
...@@ -65,7 +66,7 @@ const createMockData = () => { ...@@ -65,7 +66,7 @@ const createMockData = () => {
.collection('mcbLinks') .collection('mcbLinks')
.doc(i.toString()); .doc(i.toString());
for (let z = 1; z <= 5; z++) { for (let z = 1; z <= 1; z++) {
let mcbLinkTimerRef = fireStore let mcbLinkTimerRef = fireStore
.collection('device') .collection('device')
.doc(deviceId) .doc(deviceId)
...@@ -96,7 +97,7 @@ const createMockData = () => { ...@@ -96,7 +97,7 @@ const createMockData = () => {
.collection('subBreakers') .collection('subBreakers')
.doc(j.toString()); .doc(j.toString());
for (let z = 1; z <= 5; z++) { for (let z = 1; z <= 1; z++) {
let subBreakerTimerRef = fireStore let subBreakerTimerRef = fireStore
.collection('device') .collection('device')
.doc(deviceId) .doc(deviceId)
...@@ -127,6 +128,12 @@ const main = { ...@@ -127,6 +128,12 @@ const main = {
rcbo: 10, rcbo: 10,
}; };
const initTime = new Date();
initTime.setFullYear(2019);
initTime.setMonth(1);
initTime.setDate(0);
initTime.setSeconds(0);
const timer = { const timer = {
isActive: false, isActive: false,
isPowerOn: false, isPowerOn: false,
......
...@@ -10,9 +10,14 @@ export const GET_MAIN_DEVICE_TIMERS = 'GET_MAIN_DEVICE_TIMERS'; ...@@ -10,9 +10,14 @@ 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 = timers => ({ // export const getTimersAction = (mainDeviceTimers, mcbLinksTimers, subBreakersTimers) => ({
// type: GET_TIMERS,
// allTimers: { mainDeviceTimers, mcbLinksTimers, subBreakersTimers },
// });
export const getTimersAction = allTimers => ({
type: GET_TIMERS, type: GET_TIMERS,
timers, allTimers,
}); });
export const getMainDeviceTImersAction = mainDeviceTimers => ({ export const getMainDeviceTImersAction = mainDeviceTimers => ({
...@@ -55,6 +60,9 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -55,6 +60,9 @@ export const getTimers = () => async (dispatch, getState) => {
let mcbLinksTimers = []; let mcbLinksTimers = [];
let subBreakersTimers = []; let subBreakersTimers = [];
// let existedMcbLinks = [];
let existedSubBreakers = [];
//main device section //main device section
/*-------------------------------------*/ /*-------------------------------------*/
...@@ -68,90 +76,110 @@ export const getTimers = () => async (dispatch, getState) => { ...@@ -68,90 +76,110 @@ export const getTimers = () => async (dispatch, getState) => {
.doc(selectedDeviceId) .doc(selectedDeviceId)
.collection('Timers') .collection('Timers')
.orderBy('timer', 'asc') .orderBy('timer', 'asc')
.where('timer', '>', 0)
.get(); .get();
const selectedDeviceDetailsData = selectedDeviceDetails.data(); const selectedDeviceDetailsData = selectedDeviceDetails.data();
// const selectedDeviceTimersData = selectedDeviceTimers.data();
selectedDeviceTimers.docs.map(timer => { selectedDeviceTimers.docs.map(timer => {
mainDeviceTimers.push(timer.data()); if (timer.exists) {
mainDeviceTimers.push(
Object.assign(timer.data(), {
id: timer.id,
type: selectedDeviceDetailsData.type,
name: selectedDeviceDetailsData.name,
})
);
}
}); });
// //mcblink section //mcblink section
// /*-------------------------------------*/ /*-------------------------------------*/
// const selectedDeviceMcbLinks = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .get();
// let existedMcbLinks = []; const selectedDeviceMcbLinksDetails = await fireStore
// let selectedDeviceMcbLinksData = []; .collection('device')
.doc(selectedDeviceId)
// selectedDeviceMcbLinks.docs.map(mcbLink => { .collection('mcbLinks')
// existedMcbLinks.push(mcbLink.data().id); .get();
// selectedDeviceMcbLinksData.push(mcbLink.data());
// let mcbLinkData = mcbLink.data(); selectedDeviceMcbLinksDetails.docs.map(async mcbLink => {
if (mcbLink.exists) {
// mcbLinksTimers.push(mcbLinkData.timers); // existedMcbLinks.push(Object.assign(mcbLink.data(), { id: mcbLink.id }));
// mcbLinkData.timers.map(timer => { let mcbLinkTimers = await fireStore
// allTimersData.push( .collection('device')
// Object.assign(timer, { .doc(selectedDeviceId)
// id: mcbLink.data().id, .collection('mcbLinks')
// type: mcbLink.data().type, .doc(mcbLink.id)
// name: mcbLink.data().name, .collection('Timers')
// }) .orderBy('timer', 'asc')
// ); .get();
// });
// }); mcbLinkTimers.docs.map(mcbLinkTimer => {
// //subbreaker section if (mcbLinkTimer.exists) {
// /*-------------------------------------*/ mcbLinksTimers.push(
Object.assign(mcbLinkTimer.data(), {
// let existedSubBreakers = []; id: mcbLink.id,
// let selectedDeviceSubBreakersData = []; key: mcbLinkTimer.id,
type: mcbLink.data().type,
// selectedDeviceMcbLinksData.map(async mcbLink => { name: mcbLink.data().name,
// let selectedDeviceSubBreakers = await fireStore })
// .collection('device') );
// .doc(selectedDeviceId) }
// .collection('mcbLinks') });
// .doc(mcbLink.id.toString())
// .collection('subBreakers') //subbreaker section
// .get(); /*-------------------------------------*/
// return selectedDeviceSubBreakers.docs.map(subBreaker => { const selectedDeviceSubBreakersDetails = await fireStore
// existedSubBreakers.push([mcbLink.id, subBreaker.data().id]); .collection('device')
// selectedDeviceSubBreakersData.push(subBreaker.data()); .doc(selectedDeviceId)
.collection('mcbLinks')
// let subBreakerData = subBreaker.data(); .doc(mcbLink.id)
.collection('subBreakers')
// subBreakersTimers.push(subBreakerData.timers); .get();
// subBreakerData.timers.map(timer => { existedSubBreakers.push(
// allTimersData.push( selectedDeviceSubBreakersDetails.docs.map(subBreaker =>
// Object.assign(timer, { Object.assign(subBreaker.data(), { mcbLinkId: mcbLink.id, id: subBreaker.id })
// mcbLinkId: mcbLink.id, )
// id: subBreaker.data().id, );
// type: subBreaker.data().type,
// name: subBreaker.data().name, selectedDeviceSubBreakersDetails.docs.map(async subBreaker => {
// }) if (subBreaker.exists) {
// ); let subBreakerTimers = await fireStore
// }); .collection('device')
// }); .doc(selectedDeviceId)
// }); .collection('mcbLinks')
.doc(mcbLink.id)
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData); .collection('subBreakers')
.doc(subBreaker.id)
// const existedData = { existedMcbLinks, existedSubBreakers }; .collection('Timers')
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers); .orderBy('timer', 'asc')
.get();
// dispatch(getExistedDataAction(existedData));
subBreakerTimers.docs.map(subBreakerTimer => {
if (subBreakerTimer.exists) {
subBreakersTimers.push(
Object.assign(subBreakerTimer.data(), {
mcbLinkId: mcbLink.id,
id: subBreaker.id,
key: subBreakerTimer.id,
type: subBreaker.data().type,
name: subBreaker.data().name,
})
);
}
});
}
});
}
});
dispatch(getExistedDataAction(existedSubBreakers));
dispatch(getMainDeviceTImersAction(mainDeviceTimers)); dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getMcbLinksTimersAction(mcbLinksTimers)); dispatch(getMcbLinksTimersAction(mcbLinksTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers)); dispatch(getSubBreakersTimersAction(subBreakersTimers));
// dispatch(getTimersAction(allTimersData)); // dispatch(getTimersAction(allTimersData));
} catch (error) { } catch (error) {
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
} from '../actions/timersAction'; } from '../actions/timersAction';
const initState = { const initState = {
timers: [], allTimers: [],
mainDeviceTimers: [], mainDeviceTimers: [],
mcbLinksTimers: [], mcbLinksTimers: [],
subBreakersTimers: [], subBreakersTimers: [],
...@@ -23,7 +23,7 @@ const timersReducer = (state = initState, action) => { ...@@ -23,7 +23,7 @@ const timersReducer = (state = initState, action) => {
case GET_EXISTED_DATA: case GET_EXISTED_DATA:
return { ...state, existedData: action.existedData }; return { ...state, existedData: action.existedData };
case GET_TIMERS: case GET_TIMERS:
return { ...state, timers: action.timers }; 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: case GET_MCBLINKS_TIMERS:
......
...@@ -171,7 +171,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -171,7 +171,7 @@ class SmartMeterDetailScreen extends Component {
renderMCBLink(item, index) { renderMCBLink(item, index) {
const sb = this.state.sb; const sb = this.state.sb;
return ( return (
<View> <View key={item + index}>
<Row <Row
style={{ padding: 7 }} style={{ padding: 7 }}
onPress={() => onPress={() =>
......
...@@ -70,7 +70,7 @@ class SmartMeterScreen extends PureComponent { ...@@ -70,7 +70,7 @@ class SmartMeterScreen extends PureComponent {
style={[theme.container, theme.containerWithPadding]} style={[theme.container, theme.containerWithPadding]}
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }} //iPhoneX BottomSpace = 34 contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }} //iPhoneX BottomSpace = 34
data={allMainDeviceInfo} data={allMainDeviceInfo}
extraData={allMainDeviceInfo} extraData={this.props}
keyExtractor={(item, index) => `Card${item.deviceId}`} keyExtractor={(item, index) => `Card${item.deviceId}`}
ListEmptyComponent={() => ( ListEmptyComponent={() => (
<View> <View>
......
...@@ -27,10 +27,16 @@ import { fireStore } from '../../../firebase'; ...@@ -27,10 +27,16 @@ import { fireStore } from '../../../firebase';
import firebase from 'firebase/app'; import firebase from 'firebase/app';
import 'firebase/firestore'; import 'firebase/firestore';
const initTime = new Date();
initTime.setFullYear(2019);
initTime.setMonth(1);
initTime.setDate(0);
initTime.setSeconds(0);
const initState = { const initState = {
isActive: false, isActive: false,
isPowerOn: false, isPowerOn: false,
timer: new Date(), timer: initTime,
repeatOn: [ repeatOn: [
{ id: 0, isRepeat: false, day: 'Sunday' }, { id: 0, isRepeat: false, day: 'Sunday' },
{ id: 1, isRepeat: false, day: 'Monday' }, { id: 1, isRepeat: false, day: 'Monday' },
...@@ -63,23 +69,10 @@ class TimerScreen extends PureComponent { ...@@ -63,23 +69,10 @@ class TimerScreen extends PureComponent {
headerRight: navigation.state.params ? navigation.state.params.headerRight : null, headerRight: navigation.state.params ? navigation.state.params.headerRight : null,
}); });
// constructor(props) {
// super(props);
// this.props.navigation.setParams({
// headerRight: (
// <TouchableOpacity onPress={() => this.setState({ isAddVisible: true })}>
// <View style={{ marginRight: 17 }}>
// <Icon name="ios-add" style={{ color: color.white }} />
// </View>
// </TouchableOpacity>
// ),
// });
// }
state = { state = {
isActive: false, isActive: false,
isPowerOn: false, isPowerOn: false,
timer: new Date(), timer: initTime,
repeatOn: [ repeatOn: [
{ id: 0, isRepeat: false, day: 'Sunday' }, { id: 0, isRepeat: false, day: 'Sunday' },
{ id: 1, isRepeat: false, day: 'Monday' }, { id: 1, isRepeat: false, day: 'Monday' },
...@@ -101,30 +94,31 @@ class TimerScreen extends PureComponent { ...@@ -101,30 +94,31 @@ class TimerScreen extends PureComponent {
selectedBreaker: null, selectedBreaker: null,
selectedSubBreaker: null, selectedSubBreaker: null,
allListTimers: [],
}; };
setPickerSelectData = async () => { setPickerSelectData = () => {
let pickerSelectData = [{ label: 'Main Device', value: false }]; let pickerSelectData = [{ label: 'Main Device', value: false }];
await this.props.existedData.existedMcbLinks.map((mcbLinkId, index) => {
pickerSelectData.push({ label: `MCB Link ${mcbLinkId}`, value: index + 1 }); this.props.existedData.map((mcbLink, index) => {
pickerSelectData.push({ label: `MCB Link ${index + 1}`, value: index + 1 });
}); });
this.setState({ pickerSelectData }); this.setState({ pickerSelectData });
}; };
setExistedSubBreaker = () => { setExistedSubBreaker = () => {
let existedSubBreaker = []; let subBreakersList = 0;
this.props.existedData.existedSubBreakers.map(subBreaker => { this.props.existedData.map((mainBreaker, index) => {
if (this.state.selectedBreaker === subBreaker[0]) { if (this.state.selectedBreaker === index + 1) {
existedSubBreaker.push(subBreaker); subBreakersList = mainBreaker.length;
} }
}); });
console.log('existedSubBreaker', existedSubBreaker);
let subBreakerList = new Array(existedSubBreaker.length).fill().map((el, index) => { let subBreakerList = new Array(subBreakersList).fill().map((el, index) => {
return { id: index + 1, selected: false }; return { id: index + 1, selected: false };
}); });
console.log('subBreakerList', subBreakerList); // console.log('subBreakerList', subBreakerList);
this.setState({ subBreakerList }); this.setState({ subBreakerList });
}; };
...@@ -159,23 +153,10 @@ class TimerScreen extends PureComponent { ...@@ -159,23 +153,10 @@ class TimerScreen extends PureComponent {
const deviceId = this.props.selectedDeviceId; const deviceId = this.props.selectedDeviceId;
const { selectedSubBreaker, selectedBreaker } = this.state; const { selectedSubBreaker, selectedBreaker } = this.state;
// const data = {
// timers: [
// {
// isActive: this.state.isActive,
// isPowerOn: this.state.isPowerOn,
// timer: Number(this.state.timer),
// repeatOn: this.state.repeatOn,
// },
// ],
// };
let docRef = null; let docRef = null;
if (selectedSubBreaker) { if (selectedSubBreaker) {
docRef = fireStore.doc( docRef = fireStore.doc(`device/${deviceId}/mcbLinks/${selectedBreaker}/subBreakers/${selectedSubBreaker}`);
`device/${deviceId}/mcbLinks/${selectedBreaker}/subBreakers/${selectedSubBreaker.id}`
);
} else if (selectedBreaker) { } else if (selectedBreaker) {
docRef = fireStore.doc(`device/${deviceId}/mcbLinks/${selectedBreaker}`); docRef = fireStore.doc(`device/${deviceId}/mcbLinks/${selectedBreaker}`);
} else { } else {
...@@ -203,8 +184,7 @@ class TimerScreen extends PureComponent { ...@@ -203,8 +184,7 @@ class TimerScreen extends PureComponent {
if (prevState.selectedBreaker !== this.state.selectedBreaker) { if (prevState.selectedBreaker !== this.state.selectedBreaker) {
this.setExistedSubBreaker(); this.setExistedSubBreaker();
} }
if (prevProps.existedData.existedMcbLinks !== this.props.existedData.existedMcbLinks) { if (prevProps.existedData !== this.props.existedData) {
console.log('this.props.existedData.existedMcbLinks', this.props.existedData.existedMcbLinks);
this.setPickerSelectData(); this.setPickerSelectData();
} }
if (prevState.subBreakerList !== this.state.subBreakerList && this.state.subBreakerList) { if (prevState.subBreakerList !== this.state.subBreakerList && this.state.subBreakerList) {
...@@ -214,6 +194,15 @@ class TimerScreen extends PureComponent { ...@@ -214,6 +194,15 @@ class TimerScreen extends PureComponent {
this.setState({ selectedSubBreaker: selectedSubBreaker }); this.setState({ selectedSubBreaker: selectedSubBreaker });
} }
if (prevProps.allTimers !== this.props.allTimers) {
this.setState({
allListTimers: [
...this.props.mainDeviceTimers,
...this.props.mcbLinksTimers,
...this.props.subBreakersTimers,
],
});
}
console.log('STATE', this.state); console.log('STATE', this.state);
}; };
...@@ -229,7 +218,14 @@ class TimerScreen extends PureComponent { ...@@ -229,7 +218,14 @@ class TimerScreen extends PureComponent {
), ),
}); });
this.setExistedSubBreaker(); this.setExistedSubBreaker();
this.props.existedData.existedMcbLinks && this.setPickerSelectData(); this.props.existedData && this.setPickerSelectData();
this.setState({
allListTimers: [
...this.props.mainDeviceTimers,
...this.props.mcbLinksTimers,
...this.props.subBreakersTimers,
],
});
}; };
render() { render() {
...@@ -267,8 +263,8 @@ class TimerScreen extends PureComponent { ...@@ -267,8 +263,8 @@ class TimerScreen extends PureComponent {
{/* List Timer */} {/* List Timer */}
<FlatList <FlatList
contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }} contentContainerStyle={{ paddingBottom: isIphoneX() ? 90 : 55 }}
data={this.props.timers} data={this.props.allTimers}
extraData={this.props} extraData={this.props.allTimers}
ListEmptyComponent={() => ( ListEmptyComponent={() => (
<View> <View>
<Text style={[theme.normalText, theme.mt2]}>No timers</Text> <Text style={[theme.normalText, theme.mt2]}>No timers</Text>
...@@ -519,7 +515,10 @@ class TimerScreen extends PureComponent { ...@@ -519,7 +515,10 @@ class TimerScreen extends PureComponent {
const mapStateToProps = state => ({ const mapStateToProps = state => ({
existedData: state.timersReducer.existedData, existedData: state.timersReducer.existedData,
timers: state.timersReducer.timers, allTimers: state.timersReducer.allTimers,
mainDeviceTimers: state.timersReducer.mainDeviceTimers,
mcbLinksTimers: state.timersReducer.mcbLinksTimers,
subBreakersTimers: state.timersReducer.subBreakersTimers,
isLoading: state.timersReducer.isLoading, isLoading: state.timersReducer.isLoading,
selectedDeviceId: state.currentSelectedDeviceReducer.selectedDeviceId, selectedDeviceId: state.currentSelectedDeviceReducer.selectedDeviceId,
}); });
......
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