Commit a3e7d977 by HaOuiha

fix bug

parent 4ac09b8a
......@@ -19,21 +19,29 @@ console.disableYellowBox = true;
const Application = () => {
useEffect(() => {
fixTimerWarning();
}, []);
const batch = fireStore.batch();
return (
<Root>
<ApplicationProvider mapping={mapping} theme={myTheme}>
<Provider store={rootStore}>
<AppContainer />
</Provider>
</ApplicationProvider>
</Root>
);
};
const mainRef = fireStore.doc(`device/${deviceId}`);
const mcbLinksRef = fireStore.doc(`device/${deviceId}/mcbLinks/${mcbLinkId}`);
const subBreakersRef = fireStore.doc(`device/${deviceId}/mcbLinks/${mcbLinkId}/subBreakers/${subBreakerId}`);
export default Application;
// const mcbLinksTimerRef = fireStore.doc(`device/${deviceId}/mcbLinks/${mcbLinkId}/Timers`);
// const subBreakersTimerRef = fireStore.doc(
// `device/${deviceId}/mcbLinks/${mcbLinkId}/subBreakers/${subBreakerId}/Timers`
// );
const createMockData = () => {
// const deviceId = 'iYs6Th9Pkg1vTEDIyPa5';
const deviceId = '8998c7d5-4476-41d9-81c6-9ef2dbac2505';
const batch = fireStore.batch();
/*------------------------------*/
const mainRef = fireStore.doc(`device/${deviceId}`);
batch.set(mainRef, main);
batch.set(mcbLinksRef, mcbLinks);
batch.set(subBreakersRef, subBreakers);
for (let i = 1; i <= 5; i++) {
let mainTimerRef = fireStore
......@@ -44,27 +52,72 @@ const Application = () => {
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.commit();
}, []);
for (let z = 1; z <= 5; z++) {
let mcbLinkTimerRef = fireStore
.collection('device')
.doc(deviceId)
.collection('mcbLinks')
.doc(i.toString())
.collection('Timers')
.doc();
return (
<Root>
<ApplicationProvider mapping={mapping} theme={myTheme}>
<Provider store={rootStore}>
<AppContainer />
</Provider>
</ApplicationProvider>
</Root>
);
};
batch.set(mcbLinkTimerRef, timer);
}
export default Application;
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 <= 5; 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 deviceId = 'iYs6Th9Pkg1vTEDIyPa5';
const deviceId = '8998c7d5-4476-41d9-81c6-9ef2dbac2505';
const mcbLinkId = 1;
const subBreakerId = 2;
// const mcbLinkId = 1;
// const subBreakerId = 2;
const main = {
type: 'main',
......@@ -74,24 +127,10 @@ const main = {
rcbo: 10,
};
const mcbLinks = {
id: mcbLinkId,
type: 'mcbLink',
name: `MCB Link ${mcbLinkId}`,
description: `description ${mcbLinkId}`,
};
const subBreakers = {
id: subBreakerId,
type: 'subBreaker',
name: `Sub Breaker ${subBreakerId}`,
description: `description ${subBreakerId}`,
};
const timer = {
isActive: false,
isPowerOn: false,
timer: 1566378008,
timer: 0,
repeatOn: [
{ id: 0, isRepeat: false, day: 'Sunday' },
{ id: 1, isRepeat: false, day: 'Monday' },
......@@ -102,3 +141,32 @@ const timer = {
{ id: 6, isRepeat: false, day: 'Saturday' },
],
};
// const mcbLinks = {
// // id: mcbLinkId,
// type: 'mcbLink',
// name: `MCB Link ${mcbLinkId}`,
// description: `description ${mcbLinkId}`,
// };
// const subBreakers = {
// // id: subBreakerId,
// type: 'subBreaker',
// name: `Sub Breaker ${subBreakerId}`,
// description: `description ${subBreakerId}`,
// };
// const timer = {
// isActive: false,
// isPowerOn: false,
// timer: 1566378008,
// 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' },
// ],
// };
......@@ -45,9 +45,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
.get();
let ownerDeviceInfoData = await ownerDeviceInfo.data();
let { timers, ...rest } = ownerDeviceInfoData;
// let { timers, ...rest } = ownerDeviceInfoData;
allMainDeviceInfoData.push(Object.assign(rest, { deviceId, isSharing: false }));
allMainDeviceInfoData.push(Object.assign(ownerDeviceInfoData, { deviceId, isSharing: false }));
});
allSharingDeviceId.map(async (deviceId, index) => {
......@@ -57,9 +57,9 @@ export const getAllMainDeviceInfo = () => async (dispatch, getState) => {
.get();
let sharingDeviceInfoData = await sharingDeviceInfo.data();
let { timers, ...rest } = sharingDeviceInfoData;
// let { timers, ...rest } = sharingDeviceInfoData;
allMainDeviceInfoData.push(Object.assign(rest, { deviceId, isSharing: true }));
allMainDeviceInfoData.push(Object.assign(sharingDeviceInfoData, { deviceId, isSharing: true }));
});
// console.log('allMainDeviceInfoData', allMainDeviceInfoData);
......
......@@ -58,99 +58,215 @@ export const getTimers = () => async (dispatch, getState) => {
//main device section
/*-------------------------------------*/
const selectedDevice = await fireStore
const selectedDeviceDetails = await fireStore
.collection('device')
.doc(selectedDeviceId)
.get();
const selectedDeviceData = await selectedDevice.data();
mainDeviceTimers.push(selectedDeviceData.timers);
selectedDeviceData.timers.map(timer =>
allTimersData.push(Object.assign(timer, { type: selectedDeviceData.type, name: selectedDeviceData.name }))
);
//mcblink section
/*-------------------------------------*/
const selectedDeviceMcbLinks = await fireStore
const selectedDeviceTimers = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.collection('Timers')
.orderBy('timer', 'asc')
.where('timer', '>', 0)
.get();
let existedMcbLinks = [];
let selectedDeviceMcbLinksData = [];
const selectedDeviceDetailsData = selectedDeviceDetails.data();
// const selectedDeviceTimersData = selectedDeviceTimers.data();
selectedDeviceMcbLinks.docs.map(mcbLink => {
existedMcbLinks.push(mcbLink.data().id);
selectedDeviceMcbLinksData.push(mcbLink.data());
let mcbLinkData = mcbLink.data();
selectedDeviceTimers.docs.map(timer => {
mainDeviceTimers.push(timer.data());
});
mcbLinksTimers.push(mcbLinkData.timers);
// //mcblink section
// /*-------------------------------------*/
// const selectedDeviceMcbLinks = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .get();
// let existedMcbLinks = [];
// let selectedDeviceMcbLinksData = [];
// selectedDeviceMcbLinks.docs.map(mcbLink => {
// existedMcbLinks.push(mcbLink.data().id);
// selectedDeviceMcbLinksData.push(mcbLink.data());
// let mcbLinkData = mcbLink.data();
// mcbLinksTimers.push(mcbLinkData.timers);
// mcbLinkData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// id: mcbLink.data().id,
// type: mcbLink.data().type,
// name: mcbLink.data().name,
// })
// );
// });
// });
// //subbreaker section
// /*-------------------------------------*/
// let existedSubBreakers = [];
// let selectedDeviceSubBreakersData = [];
// selectedDeviceMcbLinksData.map(async mcbLink => {
// let selectedDeviceSubBreakers = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .doc(mcbLink.id.toString())
// .collection('subBreakers')
// .get();
// return selectedDeviceSubBreakers.docs.map(subBreaker => {
// existedSubBreakers.push([mcbLink.id, subBreaker.data().id]);
// selectedDeviceSubBreakersData.push(subBreaker.data());
// let subBreakerData = subBreaker.data();
// subBreakersTimers.push(subBreakerData.timers);
// subBreakerData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// mcbLinkId: mcbLink.id,
// id: subBreaker.data().id,
// type: subBreaker.data().type,
// name: subBreaker.data().name,
// })
// );
// });
// });
// });
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// const existedData = { existedMcbLinks, existedSubBreakers };
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// dispatch(getExistedDataAction(existedData));
mcbLinkData.timers.map(timer => {
allTimersData.push(
Object.assign(timer, {
id: mcbLink.data().id,
type: mcbLink.data().type,
name: mcbLink.data().name,
})
);
});
});
//subbreaker section
/*-------------------------------------*/
dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getMcbLinksTimersAction(mcbLinksTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers));
let existedSubBreakers = [];
let selectedDeviceSubBreakersData = [];
// dispatch(getTimersAction(allTimersData));
} catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
}
dispatch(loadingAction(false));
};
selectedDeviceMcbLinksData.map(async mcbLink => {
let selectedDeviceSubBreakers = await fireStore
.collection('device')
.doc(selectedDeviceId)
.collection('mcbLinks')
.doc(mcbLink.id.toString())
.collection('subBreakers')
.get();
// export const getTimers = () => async (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
// try {
// dispatch(loadingAction(true));
// let allTimersData = [];
// let mainDeviceTimers = [];
// let mcbLinksTimers = [];
// let subBreakersTimers = [];
return selectedDeviceSubBreakers.docs.map(subBreaker => {
existedSubBreakers.push([mcbLink.id, subBreaker.data().id]);
selectedDeviceSubBreakersData.push(subBreaker.data());
// //main device section
// /*-------------------------------------*/
let subBreakerData = subBreaker.data();
// const selectedDevice = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .get();
subBreakersTimers.push(subBreakerData.timers);
// const selectedDeviceData = await selectedDevice.data();
subBreakerData.timers.map(timer => {
allTimersData.push(
Object.assign(timer, {
mcbLinkId: mcbLink.id,
id: subBreaker.data().id,
type: subBreaker.data().type,
name: subBreaker.data().name,
})
);
});
});
});
// mainDeviceTimers.push(selectedDeviceData.timers);
console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// selectedDeviceData.timers.map(timer =>
// allTimersData.push(Object.assign(timer, { type: selectedDeviceData.type, name: selectedDeviceData.name }))
// );
const existedData = { existedMcbLinks, existedSubBreakers };
// console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// //mcblink section
// /*-------------------------------------*/
// const selectedDeviceMcbLinks = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .get();
dispatch(getExistedDataAction(existedData));
// let existedMcbLinks = [];
// let selectedDeviceMcbLinksData = [];
dispatch(getMainDeviceTImersAction(mainDeviceTimers));
dispatch(getMcbLinksTimersAction(mcbLinksTimers));
dispatch(getSubBreakersTimersAction(subBreakersTimers));
// selectedDeviceMcbLinks.docs.map(mcbLink => {
// existedMcbLinks.push(mcbLink.data().id);
// selectedDeviceMcbLinksData.push(mcbLink.data());
// let mcbLinkData = mcbLink.data();
dispatch(getTimersAction(allTimersData));
} catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
}
dispatch(loadingAction(false));
};
// mcbLinksTimers.push(mcbLinkData.timers);
// mcbLinkData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// id: mcbLink.data().id,
// type: mcbLink.data().type,
// name: mcbLink.data().name,
// })
// );
// });
// });
// //subbreaker section
// /*-------------------------------------*/
// let existedSubBreakers = [];
// let selectedDeviceSubBreakersData = [];
// selectedDeviceMcbLinksData.map(async mcbLink => {
// let selectedDeviceSubBreakers = await fireStore
// .collection('device')
// .doc(selectedDeviceId)
// .collection('mcbLinks')
// .doc(mcbLink.id.toString())
// .collection('subBreakers')
// .get();
// return selectedDeviceSubBreakers.docs.map(subBreaker => {
// existedSubBreakers.push([mcbLink.id, subBreaker.data().id]);
// selectedDeviceSubBreakersData.push(subBreaker.data());
// let subBreakerData = subBreaker.data();
// subBreakersTimers.push(subBreakerData.timers);
// subBreakerData.timers.map(timer => {
// allTimersData.push(
// Object.assign(timer, {
// mcbLinkId: mcbLink.id,
// id: subBreaker.data().id,
// type: subBreaker.data().type,
// name: subBreaker.data().name,
// })
// );
// });
// });
// });
// console.log('selectedDeviceMcbLinksData', selectedDeviceMcbLinksData);
// const existedData = { existedMcbLinks, existedSubBreakers };
// // console.log(mainDeviceTimers, mcbLinksTimers, subBreakersTimers);
// dispatch(getExistedDataAction(existedData));
// dispatch(getMainDeviceTImersAction(mainDeviceTimers));
// dispatch(getMcbLinksTimersAction(mcbLinksTimers));
// dispatch(getSubBreakersTimersAction(subBreakersTimers));
// dispatch(getTimersAction(allTimersData));
// } catch (error) {
// dispatch(errorAction(error.message || error || 'Error'));
// }
// dispatch(loadingAction(false));
// };
// export const getTimers = () => async (dispatch, getState) => {
// dispatch(loadingAction(true));
......
......@@ -24,7 +24,7 @@ class SettingScreen extends React.Component {
});
}
state = {
data: this.props.allDeviceInfo[0],
data: [],
isVisible: false,
pressQr: false,
pressMail: false,
......
......@@ -119,7 +119,7 @@ class SmartMeterDetailScreen extends Component {
state = {
mbOn: false,
sb: this.expandState(),
data: this.props.allDeviceInfo[0],
data: [],
};
renderCurrent(item, index) {
return (
......@@ -293,7 +293,7 @@ class SmartMeterDetailScreen extends Component {
}
const mapStateToProps = state => ({
allDeviceInfo: state.allDataReducer.allDeviceInfo,
allDeviceInfo: state.allMainDeviceReducer.allDeviceInfo,
});
export default connect(mapStateToProps)(SmartMeterDetailScreen);
......
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