Commit 768f47dd by HaOuiha

fix some bug and warning

parent c52a6268
......@@ -107,6 +107,7 @@ const styles = StyleSheet.create({
...theme.rowContainer,
marginBottom: 10,
height: 136,
borderColor: color.white,
borderRadius: 8,
shadowColor: '#000',
shadowOffset: {
......
......@@ -27,7 +27,7 @@
"react-native-chart-kit": "^3.2.1",
"react-native-date-picker": "^2.7.0",
"react-native-elements": "^1.1.0",
"react-native-gesture-handler": "^1.3.0",
"react-native-gesture-handler": "^1.4.1",
"react-native-linear-gradient": "^2.5.4",
"react-native-modalbox": "^1.7.1",
"react-native-permissions": "^1.2.0",
......@@ -36,7 +36,7 @@
"react-native-reanimated": "^1.2.0",
"react-native-screens": "^2.0.0-alpha.3",
"react-native-slider": "^0.11.0",
"react-native-svg": "^9.7.1",
"react-native-svg": "^9.9.4",
"react-native-svg-charts": "^5.3.0",
"react-native-swipe-list-view": "^2.0.0",
"react-native-swipeout": "^2.3.6",
......@@ -59,7 +59,7 @@
"babel-jest": "^24.8.0",
"eslint": "^6.0.1",
"jest": "^24.8.0",
"jetifier": "^1.6.3",
"jetifier": "^1.6.4",
"metro-react-native-babel-preset": "^0.55.0",
"react-test-renderer": "16.8.6"
},
......
......@@ -128,8 +128,6 @@ export const getTimers = () => async (dispatch, getState) => {
mcbLinkId: mcbLink.id,
subBreakerId: subBreaker.id,
isPowerOn: false,
// isPowerOn:
// shadow[`ML${mcbLink.id}`][`L${mcbLink.id}B${subBreaker.id}`] === 1 ? true : false,
})
)
);
......@@ -415,66 +413,66 @@ export const deleteTimer = selectedData => async (dispatch, getState) => {
}
};
export const writeTimersToShadow = () => async (dispatch, getState) => {
const { currentSelectedDeviceReducer, timersReducer } = getState();
const { allTimers } = timersReducer;
const { currentSelectedData } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId;
const URL = `${baseURL}/shadow/${selectedDeviceId}`;
const idToken = await app.auth().currentUser.getIdToken(true);
const groupTypeData = _.groupBy(allTimers, 'type');
const tempSubBreakerTimersData = _.groupBy(
groupTypeData.subBreaker,
tempSubBreakerTimersData =>
'L' + tempSubBreakerTimersData.mcbLinkId + 'B' + tempSubBreakerTimersData.subBreakerId + 'T'
);
const tempMainBreakerTimersData = { MAB1T: groupTypeData.main };
console.log(groupTypeData);
console.log('------------------------------');
console.log(tempMainBreakerTimersData);
console.log(tempSubBreakerTimersData);
//convert Timer to shadow format
const mainBreakerTimersData = tempMainBreakerTimersData.MAB1T.reduce((accumulator, timer, index) => {
const isActive = timer.isActive ? '1' : '0';
const isPowerOn = timer.isPowerOn ? '1' : '0';
const repeatOn = () => {
let binaryFormat = timer.repeatOn
.map(item => (item.isRepeat ? '1' : '0'))
.toString()
.replace(/\,/g, '');
const decimalFormat = parseInt(Number(binaryFormat), 2);
return decimalFormat;
};
const hour = moment(timer.timer).format('HH');
const minute = moment(timer.timer).format('mm');
let timerShadowFormat = { [`T${index + 1}`]: `${isActive},${isPowerOn},${repeatOn()},${hour},${minute}` };
return { ...accumulator, ...timerShadowFormat };
}, {});
console.log('mainBreakerTimersData', mainBreakerTimersData);
const data = { data: { L1B1T: { T1: '1,1,127,8,0' } } };
const options = {
method: 'PUT',
headers: { Authorization: `Token ${idToken}`, 'content-Type': 'text/plain' },
url: URL,
data: JSON.stringify(data).replace(/\"/g, ''),
};
// export const writeTimersToShadow = () => async (dispatch, getState) => {
// const { currentSelectedDeviceReducer, timersReducer } = getState();
// const { allTimers } = timersReducer;
// const { currentSelectedData } = currentSelectedDeviceReducer;
// const selectedDeviceId = currentSelectedData.deviceId;
// const URL = `${baseURL}/shadow/${selectedDeviceId}`;
// const idToken = await app.auth().currentUser.getIdToken(true);
// const groupTypeData = _.groupBy(allTimers, 'type');
// const tempSubBreakerTimersData = _.groupBy(
// groupTypeData.subBreaker,
// tempSubBreakerTimersData =>
// 'L' + tempSubBreakerTimersData.mcbLinkId + 'B' + tempSubBreakerTimersData.subBreakerId + 'T'
// );
// const tempMainBreakerTimersData = { MAB1T: groupTypeData.main };
// console.log(groupTypeData);
// console.log('------------------------------');
// console.log(tempMainBreakerTimersData);
// console.log(tempSubBreakerTimersData);
// //convert Timer to shadow format
// const mainBreakerTimersData = tempMainBreakerTimersData.MAB1T.reduce((accumulator, timer, index) => {
// const isActive = timer.isActive ? '1' : '0';
// const isPowerOn = timer.isPowerOn ? '1' : '0';
// const repeatOn = () => {
// let binaryFormat = timer.repeatOn
// .map(item => (item.isRepeat ? '1' : '0'))
// .toString()
// .replace(/\,/g, '');
// const decimalFormat = parseInt(Number(binaryFormat), 2);
// return decimalFormat;
// };
// const hour = moment(timer.timer).format('HH');
// const minute = moment(timer.timer).format('mm');
// let timerShadowFormat = { [`T${index + 1}`]: `${isActive},${isPowerOn},${repeatOn()},${hour},${minute}` };
// return { ...accumulator, ...timerShadowFormat };
// }, {});
// console.log('mainBreakerTimersData', mainBreakerTimersData);
// const data = { data: { L1B1T: { T1: '1,1,127,8,0' } } };
// const options = {
// method: 'PUT',
// headers: { Authorization: `Token ${idToken}`, 'content-Type': 'text/plain' },
// url: URL,
// data: JSON.stringify(data).replace(/\"/g, ''),
// };
try {
const response = await axios(options);
console.log(response);
} catch (error) {
console.log(error);
}
};
// try {
// const response = await axios(options);
// console.log(response);
// } catch (error) {
// console.log(error);
// }
// };
// export const deleteTimer2 = selectedData => async (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
......
import React from 'react';
import { Text, Tab, Tabs, ScrollableTab, View, Card, Icon } from 'native-base';
import { connect } from 'react-redux';
import { StyleSheet, TextInput, Image } from 'react-native';
import { StyleSheet, TextInput, Image, TouchableOpacity } from 'react-native';
import { theme, color } from '../../../constants/Styles';
import { HeaderButtons, Item } from 'react-navigation-header-buttons';
import IoniconsHeaderButton from '../../../components/IoniconsHeaderButton';
import { Switch, FlatList, ScrollView, TouchableOpacity } from 'react-native-gesture-handler';
import { Switch, FlatList, ScrollView } from 'react-native-gesture-handler';
import { width, height } from '../../../constants/Layout';
import {
getCurrentSelectedShadow,
......@@ -25,11 +25,7 @@ class McbLinkScreen extends React.Component {
title: navigation.getParam('mcbLink').name,
headerLeft: (
<HeaderButtons HeaderButtonComponent={IoniconsHeaderButton}>
<Item
title="back"
iconName="ios-arrow-back"
onPress={() => navigation.navigate('SmartMeterDetail')}
/>
<Item title="back" iconName="ios-arrow-back" onPress={() => navigation.pop()} />
</HeaderButtons>
),
// remove line between header and tab bar
......@@ -206,7 +202,10 @@ class McbLinkScreen extends React.Component {
>
{item.type ? (
<Image
style={styles.electronicIcon}
style={[
styles.electronicIcon,
{ tintColor: color.primary, resizeMode: 'contain' },
]}
source={getDeviceIcon(item.type)}
/>
) : (
......@@ -229,7 +228,7 @@ class McbLinkScreen extends React.Component {
}
}}
ItemSeparatorComponent={() => <View style={{ margin: 5 }} />}
keyExtractor={({ item, index }) => {
keyExtractor={(item, index) => {
`elec${index}`;
}}
key={`scrollPage${index}`}
......@@ -316,6 +315,7 @@ class McbLinkScreen extends React.Component {
if (item.type === 'empty') {
return <Card style={styles.electronicCard} transparent />;
} else {
const dynamicColor = item.type === deviceType ? color.white : color.primary;
return (
<Card
style={[
......@@ -334,10 +334,8 @@ class McbLinkScreen extends React.Component {
style={[
styles.electronicIcon,
{
tintColor:
item.type === deviceType
? color.white
: color.primary,
tintColor: dynamicColor,
resizeMode: 'contain',
},
]}
source={getDeviceIcon(item.type)}
......@@ -359,7 +357,7 @@ class McbLinkScreen extends React.Component {
);
}
}}
keyExtractor={({ item, index }) => `device${index}`}
keyExtractor={(item, index) => `device${index}`}
/>
</View>
</ScrollView>
......@@ -443,10 +441,9 @@ const styles = StyleSheet.create({
borderColor: 'transparent',
},
electronicIcon: {
tintColor: color.primary,
// tintColor: color.primary,
width: 30,
height: 30,
resizeMode: 'contain',
marginBottom: 10,
},
electronictext: {
......
......@@ -251,7 +251,6 @@ class TimerScreen extends PureComponent {
selectedSubBreaker: null,
});
}
this.props.writeTimersToShadow();
}
if (prevProps.existedMcbLinksData !== this.props.existedMcbLinksData) {
this.setPickerSelectData();
......
......@@ -4441,7 +4441,7 @@ jest@^24.8.0:
import-local "^2.0.0"
jest-cli "^24.9.0"
jetifier@^1.6.2, jetifier@^1.6.3:
jetifier@^1.6.2, jetifier@^1.6.4:
version "1.6.4"
resolved "https://registry.yarnpkg.com/jetifier/-/jetifier-1.6.4.tgz#6159db8e275d97980d26162897a0648b6d4a3222"
integrity sha512-+f/4OLeqY8RAmXnonI1ffeY1DR8kMNJPhv5WMFehchf7U71cjMQVKkOz1n6asz6kfVoAqKNWJz1A/18i18AcXA==
......@@ -6244,7 +6244,7 @@ react-native-elements@^1.1.0:
react-native-ratings "^6.3.0"
react-native-status-bar-height "^2.2.0"
react-native-gesture-handler@^1.3.0:
react-native-gesture-handler@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.4.1.tgz#c38d9e57637b95e221722a79f2bafac62e3aeb21"
integrity sha512-Ffcs+SbEbkGaal0CClYL+v7A9y4OA5G5lW01qrzjxaqASp5C8BfnWSKuqYKE00s6bLwE5L4xnlHkG0yIxAtbrQ==
......@@ -6365,7 +6365,7 @@ react-native-svg-charts@^5.3.0:
d3-shape "^1.0.6"
prop-types "^15.6.0"
react-native-svg@^9.7.1:
react-native-svg@^9.9.4:
version "9.9.4"
resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-9.9.4.tgz#31070eeb68fb6e8dc0c0828c87687da3e0679102"
integrity sha512-tROcwGg69hEF+eUoYIIn8Aldq57ZZqq5gjxiILegK0EXc4XAoeWxOzfZiPQJbykY/FSYuT8IkKIsPF9ZGFlLqQ==
......
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