Commit bad299bd by HaOuiha

fix bug

parent 76b8cbc9
......@@ -12,18 +12,13 @@ import { Provider } from 'react-redux';
import rootStore from './reduxStore';
import { Root } from 'native-base';
import { fixTimerWarning } from './utils/fixTimerWarning';
import { YellowBox } from 'react-native';
import { useScreens } from 'react-native-screens';
import { fireStore } from './firebase';
console.disableYellowBox = true;
const Application = () => {
useEffect(() => {
// useScreens();
fixTimerWarning();
YellowBox.ignoreWarnings(['Warning:']);
// createMockData();
}, []);
return (
......@@ -38,147 +33,3 @@ const Application = () => {
};
export default Application;
const createMockData = () => {
// 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());
// 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(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 mcbLinkId = 1;
// const subBreakerId = 2;
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' },
],
};
// 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' },
// ],
// };
......@@ -149,24 +149,24 @@ export const setMainStatus = value => async (dispatch, getState) => {
console.log(data);
console.log(JSON.stringify(data).replace(/\"/g, ''));
// const options = {
// method: 'PUT',
// headers: { Authorization: `Token ${idToken}`, 'Content-Type': 'text/plain' },
// url: URL,
// data: JSON.stringify(data),
// };
const options = {
method: 'PUT',
headers: { Authorization: `Token ${idToken}`, 'content-Type': 'text/plain' },
url: URL,
data: JSON.stringify(data).replace(/\"/g, ''),
};
try {
const res = await fetch(URL, {
method: 'PUT',
headers: { Authorization: `Token ${idToken}`, 'Content-Type': 'text/plain' },
body: JSON.stringify(data).replace(/\"/g, ''),
}).then(response => response.json());
// const res = await fetch(URL, {
// method: 'PUT',
// headers: { Authorization: `Token ${idToken}`, 'Content-Type': 'text/plain' },
// body: JSON.stringify(data).replace(/\"/g, ''),
// }).then(response => response.json());
console.log(res);
// console.log(res);
// const response = await axios(options);
// console.log(response);
const response = await axios(options);
console.log(response);
} catch (error) {
console.log(error);
}
......
......@@ -38,6 +38,14 @@ class SmartMeterScreen extends PureComponent {
});
};
componentDidUpdate = (prevProps, prevState) => {
if (prevProps.allMainDeviceInfo !== this.props.allMainDeviceInfo) {
this.setState({
data: this.props.allMainDeviceInfo,
});
}
};
renderItem = ({ item, index }) => {
return (
<MeterCard
......@@ -104,6 +112,7 @@ class SmartMeterScreen extends PureComponent {
style={[theme.container]}
contentContainerStyle={[theme.containerWithPadding, { paddingBottom: isIphoneX() ? 90 : 55 }]} //iPhoneX BottomSpace = 34
data={data}
extraData={this.props}
keyExtractor={(item, index) => item.deviceId}
ItemSeparatorComponent={() => <View style={theme.mt1} />}
ListEmptyComponent={() => (
......
......@@ -6,6 +6,7 @@ import { width } from '../../constants/Layout';
import app from '../../firebase';
import { connect } from 'react-redux';
import { getCurrentUser } from '../../reduxStore/actions/cerrentUserAction';
import { fireStore } from '../../firebase';
class AuthLoadingScreen extends Component {
static navigationOptions = {
......@@ -25,7 +26,7 @@ class AuthLoadingScreen extends Component {
if (this._isMounted) {
this.setState({ isShowImg: false });
}
}, 800); // 1200
}, 900); // 1200
};
_bootstrapAsync = async () => {
......@@ -43,7 +44,7 @@ class AuthLoadingScreen extends Component {
// console.log(idToken);
await this.props.getCurrentUser(user);
this.props.navigation.navigate(RememberedLogin === 'true' ? 'Main' : 'Login');
// this.props.navigation.navigate(false ? 'Main' : 'Login');
// createMockData();
} else {
this.props.navigation.navigate(alreadyLaunched === 'true' ? 'Login' : 'Onboarding');
}
......@@ -89,3 +90,105 @@ export default connect(
null,
mapDispatchToProps
)(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' },
],
};
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