Commit 11217db6 by HaOuiha

update

parent 9d29eb67
...@@ -7,6 +7,8 @@ export const GET_CURRENT_SELECTED_DATA = 'GET_CURRENT_SELECTED_DATA'; ...@@ -7,6 +7,8 @@ export const GET_CURRENT_SELECTED_DATA = 'GET_CURRENT_SELECTED_DATA';
export const GET_CURRENT_SELECTED_DATA_LOADING = 'GET_CURRENT_SELECTED_DATA_LOADING'; export const GET_CURRENT_SELECTED_DATA_LOADING = 'GET_CURRENT_SELECTED_DATA_LOADING';
export const GET_CURRENT_SELECTED_DATA_ERROR = 'GET_CURRENT_SELECTED_DATA_ERROR'; export const GET_CURRENT_SELECTED_DATA_ERROR = 'GET_CURRENT_SELECTED_DATA_ERROR';
export const GET_CURRENT_SELECTED_SHADOW = 'GET_CURRENT_SELECTED_SHADOW';
export const getCurrentSelectedDataAction = currentSelectedData => ({ export const getCurrentSelectedDataAction = currentSelectedData => ({
type: GET_CURRENT_SELECTED_DATA, type: GET_CURRENT_SELECTED_DATA,
currentSelectedData, currentSelectedData,
...@@ -22,35 +24,53 @@ export const errorAction = error => ({ ...@@ -22,35 +24,53 @@ export const errorAction = error => ({
error, error,
}); });
export const getCurrentSelectedData = deviceId => async dispatch => { export const getCurrentSelectedShadowAction = shadow => ({
try { type: GET_CURRENT_SELECTED_SHADOW,
dispatch(loadingAction(true)); shadow,
const currentSelectedDevice = await fireStore });
.collection('device')
.doc(deviceId)
.get();
const currentSelectedDeviceData = await currentSelectedDevice.data(); export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId;
const URL = `${baseURL}/shadow/${deviceId || selectedDeviceId}`;
const idToken = await app.auth().currentUser.getIdToken(true); const idToken = await app.auth().currentUser.getIdToken(true);
console.log(idToken);
const URL = `${baseURL}/shadow/${deviceId}`;
const options = { const options = {
headers: { Authorization: `Token ${idToken}` }, headers: { Authorization: `Token ${idToken}` },
url: URL, url: URL,
}; };
console.log(URL);
try { try {
const getShadow = await axios(options); const getShadow = async () => {
console.log(getShadow); try {
const response = await axios(options);
return response.data.shadow.value;
} catch (error) { } catch (error) {
alert(error); alert(error);
return null;
} }
};
const shadowData = await getShadow();
dispatch(getCurrentSelectedShadowAction(shadowData));
} catch (error) {
dispatch(errorAction(error.message || error || 'Error'));
}
};
export const getCurrentSelectedData = deviceId => async dispatch => {
try {
dispatch(loadingAction(true));
const currentSelectedDevice = await fireStore
.collection('device')
.doc(deviceId)
.get();
const currentSelectedDeviceData = await currentSelectedDevice.data();
const currentSelectedDeviceDataMoreInfo = { ...currentSelectedDeviceData, deviceId: currentSelectedDevice.id }; const currentSelectedDeviceDataMoreInfo = { ...currentSelectedDeviceData, deviceId: currentSelectedDevice.id };
dispatch(loadingAction(false)); dispatch(loadingAction(false));
return dispatch(getCurrentSelectedDataAction(currentSelectedDeviceDataMoreInfo));
dispatch(getCurrentSelectedDataAction(currentSelectedDeviceDataMoreInfo));
} catch (error) { } catch (error) {
dispatch(errorAction(error.message || error || 'Error')); dispatch(errorAction(error.message || error || 'Error'));
dispatch(loadingAction(false)); dispatch(loadingAction(false));
...@@ -61,7 +81,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => { ...@@ -61,7 +81,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
const { currentSelectedDeviceReducer } = getState(); const { currentSelectedDeviceReducer } = getState();
const { currentSelectedData } = currentSelectedDeviceReducer; const { currentSelectedData } = currentSelectedDeviceReducer;
const selectedDeviceId = currentSelectedData.deviceId; const selectedDeviceId = currentSelectedData.deviceId;
const { deviceId, isSharing, ...currentSelectedMainData } = currentSelectedData; const { deviceId, ...currentSelectedMainData } = currentSelectedData;
const getNewData = () => { const getNewData = () => {
switch (type) { switch (type) {
......
...@@ -2,10 +2,12 @@ import { ...@@ -2,10 +2,12 @@ import {
GET_CURRENT_SELECTED_DATA, GET_CURRENT_SELECTED_DATA,
GET_CURRENT_SELECTED_DATA_LOADING, GET_CURRENT_SELECTED_DATA_LOADING,
GET_CURRENT_SELECTED_DATA_ERROR, GET_CURRENT_SELECTED_DATA_ERROR,
GET_CURRENT_SELECTED_SHADOW,
} from '../actions/currentSelectedAction'; } from '../actions/currentSelectedAction';
const initState = { const initState = {
currentSelectedData: {}, currentSelectedData: {},
shadow: null,
isLoading: true, isLoading: true,
error: null, error: null,
}; };
...@@ -14,6 +16,8 @@ const currentSelectedDeviceReducer = (state = initState, action) => { ...@@ -14,6 +16,8 @@ const currentSelectedDeviceReducer = (state = initState, action) => {
switch (action.type) { switch (action.type) {
case GET_CURRENT_SELECTED_DATA: case GET_CURRENT_SELECTED_DATA:
return { ...state, currentSelectedData: action.currentSelectedData }; return { ...state, currentSelectedData: action.currentSelectedData };
case GET_CURRENT_SELECTED_SHADOW:
return { ...state, shadow: action.shadow };
case GET_CURRENT_SELECTED_DATA_LOADING: case GET_CURRENT_SELECTED_DATA_LOADING:
return { ...state, isLoading: action.isLoading }; return { ...state, isLoading: action.isLoading };
case GET_CURRENT_SELECTED_DATA_ERROR: case GET_CURRENT_SELECTED_DATA_ERROR:
......
...@@ -4,7 +4,7 @@ import { color, theme } from '../../../constants/Styles'; ...@@ -4,7 +4,7 @@ import { color, theme } from '../../../constants/Styles';
import { FlatList, StyleSheet, ActivityIndicator, RefreshControl, ScrollView, Platform } from 'react-native'; import { FlatList, StyleSheet, ActivityIndicator, RefreshControl, ScrollView, Platform } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler'; import { TouchableOpacity } from 'react-native-gesture-handler';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { getCurrentSelectedData } from '../../../reduxStore/actions/currentSelectedAction'; import { getCurrentSelectedData, getCurrentSelectedShadow } from '../../../reduxStore/actions/currentSelectedAction';
import { getTimers } from '../../../reduxStore/actions/timersAction'; import { getTimers } from '../../../reduxStore/actions/timersAction';
import { isIphoneX } from '../../../utils/isPhoneX'; import { isIphoneX } from '../../../utils/isPhoneX';
...@@ -48,6 +48,7 @@ class SmartMeterDetailScreen extends Component { ...@@ -48,6 +48,7 @@ class SmartMeterDetailScreen extends Component {
getData = async () => { getData = async () => {
const deviceId = this.props.navigation.getParam('deviceId'); const deviceId = this.props.navigation.getParam('deviceId');
await this.props.getCurrentSelectedData(deviceId); await this.props.getCurrentSelectedData(deviceId);
await this.props.getCurrentSelectedShadow(deviceId);
this.props.getTimers(); this.props.getTimers();
}; };
...@@ -68,6 +69,10 @@ class SmartMeterDetailScreen extends Component { ...@@ -68,6 +69,10 @@ class SmartMeterDetailScreen extends Component {
} }
}; };
componentWillMount = () => {
this._mcbLinksListMounted = false;
};
setMainCardData = async () => { setMainCardData = async () => {
const { currentSelectedData } = this.props; const { currentSelectedData } = this.props;
this.setState({ this.setState({
...@@ -312,6 +317,7 @@ const mapStateToProps = state => ({ ...@@ -312,6 +317,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = { const mapDispatchToProps = {
getCurrentSelectedData, getCurrentSelectedData,
getCurrentSelectedShadow,
getTimers, getTimers,
}; };
......
...@@ -7,7 +7,6 @@ import { HeaderButtons, Item } from 'react-navigation-header-buttons'; ...@@ -7,7 +7,6 @@ import { HeaderButtons, Item } from 'react-navigation-header-buttons';
import IoniconsHeaderButton from '../../../components/IoniconsHeaderButton'; import IoniconsHeaderButton from '../../../components/IoniconsHeaderButton';
import { isIphoneX } from '../../../utils/isPhoneX'; import { isIphoneX } from '../../../utils/isPhoneX';
import { getAllMainDeviceInfo } from '../../../reduxStore/actions/allMainDeviceAction'; import { getAllMainDeviceInfo } from '../../../reduxStore/actions/allMainDeviceAction';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { SearchBar } from 'react-native-elements'; import { SearchBar } from 'react-native-elements';
...@@ -55,6 +54,7 @@ class SmartMeterScreen extends PureComponent { ...@@ -55,6 +54,7 @@ class SmartMeterScreen extends PureComponent {
const { allMainDeviceInfo, isLoading, error } = this.props; const { allMainDeviceInfo, isLoading, error } = this.props;
return !error ? ( return !error ? (
<>
<FlatList <FlatList
refreshControl={ refreshControl={
<RefreshControl <RefreshControl
...@@ -83,6 +83,7 @@ class SmartMeterScreen extends PureComponent { ...@@ -83,6 +83,7 @@ class SmartMeterScreen extends PureComponent {
)} )}
renderItem={(item, index) => this.renderItem(item)} renderItem={(item, index) => this.renderItem(item)}
/> />
</>
) : ( ) : (
<View> <View>
<Text>{error}</Text> <Text>{error}</Text>
......
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