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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
18 deletions
+49
-18
reduxStore/actions/currentSelectedAction.js
+36
-16
reduxStore/reducers/currentSelectedReducer.js
+4
-0
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+7
-1
screens/Private/SmartMeterScreen/SmartMeterScreen.js
+2
-1
No files found.
reduxStore/actions/currentSelectedAction.js
View file @
11217db6
...
@@ -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
)
{
...
...
reduxStore/reducers/currentSelectedReducer.js
View file @
11217db6
...
@@ -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
:
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
11217db6
...
@@ -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
,
};
};
...
...
screens/Private/SmartMeterScreen/SmartMeterScreen.js
View file @
11217db6
...
@@ -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
>
...
...
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