Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
safetcut-app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
atichat
safetcut-app
Commits
11217db6
Commit
11217db6
authored
Sep 05, 2019
by
HaOuiha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
9d29eb67
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
49 deletions
+80
-49
reduxStore/actions/currentSelectedAction.js
+39
-19
reduxStore/reducers/currentSelectedReducer.js
+4
-0
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+7
-1
screens/Private/SmartMeterScreen/SmartMeterScreen.js
+30
-29
No files found.
reduxStore/actions/currentSelectedAction.js
View file @
11217db6
...
...
@@ -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_ERROR
=
'GET_CURRENT_SELECTED_DATA_ERROR'
;
export
const
GET_CURRENT_SELECTED_SHADOW
=
'GET_CURRENT_SELECTED_SHADOW'
;
export
const
getCurrentSelectedDataAction
=
currentSelectedData
=>
({
type
:
GET_CURRENT_SELECTED_DATA
,
currentSelectedData
,
...
...
@@ -22,6 +24,40 @@ export const errorAction = error => ({
error
,
});
export
const
getCurrentSelectedShadowAction
=
shadow
=>
({
type
:
GET_CURRENT_SELECTED_SHADOW
,
shadow
,
});
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
options
=
{
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
url
:
URL
,
};
try
{
const
getShadow
=
async
()
=>
{
try
{
const
response
=
await
axios
(
options
);
return
response
.
data
.
shadow
.
value
;
}
catch
(
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
));
...
...
@@ -31,26 +67,10 @@ export const getCurrentSelectedData = deviceId => async dispatch => {
.
get
();
const
currentSelectedDeviceData
=
await
currentSelectedDevice
.
data
();
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
console
.
log
(
idToken
);
const
URL
=
`
${
baseURL
}
/shadow/
${
deviceId
}
`
;
const
options
=
{
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
url
:
URL
,
};
console
.
log
(
URL
);
try
{
const
getShadow
=
await
axios
(
options
);
console
.
log
(
getShadow
);
}
catch
(
error
)
{
alert
(
error
);
}
const
currentSelectedDeviceDataMoreInfo
=
{
...
currentSelectedDeviceData
,
deviceId
:
currentSelectedDevice
.
id
};
dispatch
(
loadingAction
(
false
));
return
dispatch
(
getCurrentSelectedDataAction
(
currentSelectedDeviceDataMoreInfo
));
dispatch
(
getCurrentSelectedDataAction
(
currentSelectedDeviceDataMoreInfo
));
}
catch
(
error
)
{
dispatch
(
errorAction
(
error
.
message
||
error
||
'Error'
));
dispatch
(
loadingAction
(
false
));
...
...
@@ -61,7 +81,7 @@ export const updateDetail = (type, value) => async (dispatch, getState) => {
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
{
deviceId
,
isSharing
,
...
currentSelectedMainData
}
=
currentSelectedData
;
const
{
deviceId
,
...
currentSelectedMainData
}
=
currentSelectedData
;
const
getNewData
=
()
=>
{
switch
(
type
)
{
...
...
reduxStore/reducers/currentSelectedReducer.js
View file @
11217db6
...
...
@@ -2,10 +2,12 @@ import {
GET_CURRENT_SELECTED_DATA
,
GET_CURRENT_SELECTED_DATA_LOADING
,
GET_CURRENT_SELECTED_DATA_ERROR
,
GET_CURRENT_SELECTED_SHADOW
,
}
from
'../actions/currentSelectedAction'
;
const
initState
=
{
currentSelectedData
:
{},
shadow
:
null
,
isLoading
:
true
,
error
:
null
,
};
...
...
@@ -14,6 +16,8 @@ const currentSelectedDeviceReducer = (state = initState, action) => {
switch
(
action
.
type
)
{
case
GET_CURRENT_SELECTED_DATA
:
return
{
...
state
,
currentSelectedData
:
action
.
currentSelectedData
};
case
GET_CURRENT_SELECTED_SHADOW
:
return
{
...
state
,
shadow
:
action
.
shadow
};
case
GET_CURRENT_SELECTED_DATA_LOADING
:
return
{
...
state
,
isLoading
:
action
.
isLoading
};
case
GET_CURRENT_SELECTED_DATA_ERROR
:
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
11217db6
...
...
@@ -4,7 +4,7 @@ import { color, theme } from '../../../constants/Styles';
import
{
FlatList
,
StyleSheet
,
ActivityIndicator
,
RefreshControl
,
ScrollView
,
Platform
}
from
'react-native'
;
import
{
TouchableOpacity
}
from
'react-native-gesture-handler'
;
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
{
isIphoneX
}
from
'../../../utils/isPhoneX'
;
...
...
@@ -48,6 +48,7 @@ class SmartMeterDetailScreen extends Component {
getData
=
async
()
=>
{
const
deviceId
=
this
.
props
.
navigation
.
getParam
(
'deviceId'
);
await
this
.
props
.
getCurrentSelectedData
(
deviceId
);
await
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
this
.
props
.
getTimers
();
};
...
...
@@ -68,6 +69,10 @@ class SmartMeterDetailScreen extends Component {
}
};
componentWillMount
=
()
=>
{
this
.
_mcbLinksListMounted
=
false
;
};
setMainCardData
=
async
()
=>
{
const
{
currentSelectedData
}
=
this
.
props
;
this
.
setState
({
...
...
@@ -312,6 +317,7 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
{
getCurrentSelectedData
,
getCurrentSelectedShadow
,
getTimers
,
};
...
...
screens/Private/SmartMeterScreen/SmartMeterScreen.js
View file @
11217db6
...
...
@@ -7,7 +7,6 @@ import { HeaderButtons, Item } from 'react-navigation-header-buttons';
import
IoniconsHeaderButton
from
'../../../components/IoniconsHeaderButton'
;
import
{
isIphoneX
}
from
'../../../utils/isPhoneX'
;
import
{
getAllMainDeviceInfo
}
from
'../../../reduxStore/actions/allMainDeviceAction'
;
import
{
connect
}
from
'react-redux'
;
import
{
SearchBar
}
from
'react-native-elements'
;
...
...
@@ -55,34 +54,36 @@ class SmartMeterScreen extends PureComponent {
const
{
allMainDeviceInfo
,
isLoading
,
error
}
=
this
.
props
;
return
!
error
?
(
<
FlatList
refreshControl
=
{
<
RefreshControl
refreshing
=
{
isLoading
}
onRefresh
=
{
this
.
getData
}
title
=
"Pull to refresh"
tintColor
=
{
color
.
primary
}
titleColor
=
{
color
.
darkGrey
}
colors
=
{[
color
.
primary
]}
/
>
}
style
=
{[
theme
.
container
]}
contentContainerStyle
=
{[
theme
.
containerWithPadding
,
{
paddingBottom
:
isIphoneX
()
?
90
:
55
}]}
//iPhoneX BottomSpace = 34
data
=
{
allMainDeviceInfo
}
keyExtractor
=
{(
item
,
index
)
=>
item
.
deviceId
}
ItemSeparatorComponent
=
{()
=>
<
View
style
=
{
theme
.
mt1
}
/>
}
ListEmptyComponent
=
{()
=>
(
<
View
>
<
Text
style
=
{[
theme
.
normalText
,
{
marginTop
:
20
}]}
>
{
isLoading
?
''
:
this
.
_isMounted
?
'No Device Connected'
:
''
}
<
/Text
>
<
/View
>
)}
ListHeaderComponent
=
{()
=>
(
<
Text
style
=
{[
theme
.
smallTitle
,
theme
.
textDark
,
{
marginBottom
:
10
}]}
>
Smart
Device
<
/Text
>
)}
renderItem
=
{(
item
,
index
)
=>
this
.
renderItem
(
item
)}
/
>
<>
<
FlatList
refreshControl
=
{
<
RefreshControl
refreshing
=
{
isLoading
}
onRefresh
=
{
this
.
getData
}
title
=
"Pull to refresh"
tintColor
=
{
color
.
primary
}
titleColor
=
{
color
.
darkGrey
}
colors
=
{[
color
.
primary
]}
/
>
}
style
=
{[
theme
.
container
]}
contentContainerStyle
=
{[
theme
.
containerWithPadding
,
{
paddingBottom
:
isIphoneX
()
?
90
:
55
}]}
//iPhoneX BottomSpace = 34
data
=
{
allMainDeviceInfo
}
keyExtractor
=
{(
item
,
index
)
=>
item
.
deviceId
}
ItemSeparatorComponent
=
{()
=>
<
View
style
=
{
theme
.
mt1
}
/>
}
ListEmptyComponent
=
{()
=>
(
<
View
>
<
Text
style
=
{[
theme
.
normalText
,
{
marginTop
:
20
}]}
>
{
isLoading
?
''
:
this
.
_isMounted
?
'No Device Connected'
:
''
}
<
/Text
>
<
/View
>
)}
ListHeaderComponent
=
{()
=>
(
<
Text
style
=
{[
theme
.
smallTitle
,
theme
.
textDark
,
{
marginBottom
:
10
}]}
>
Smart
Device
<
/Text
>
)}
renderItem
=
{(
item
,
index
)
=>
this
.
renderItem
(
item
)}
/
>
<
/
>
)
:
(
<
View
>
<
Text
>
{
error
}
<
/Text
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment