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
41de80af
Commit
41de80af
authored
Sep 13, 2019
by
Tonk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto stash before merge of "ejectedExpo" and "origin/ejectedExpo"
parent
bad299bd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
33 deletions
+63
-33
components/MeterCard.js
+41
-5
reduxStore/actions/currentSelectedAction.js
+3
-24
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+19
-4
No files found.
components/MeterCard.js
View file @
41de80af
...
...
@@ -3,20 +3,45 @@ import { View, Row, Icon, Text } from 'native-base';
import
{
Image
,
StyleSheet
,
Platform
}
from
'react-native'
;
import
{
BaseButton
,
TouchableOpacity
}
from
'react-native-gesture-handler'
;
import
{
color
,
theme
}
from
'../constants/Styles'
;
import
{
connect
}
from
'react-redux'
;
import
{
getCurrentSelectedShadow
}
from
'../reduxStore/actions/currentSelectedAction'
;
class
MeterCard
extends
Component
{
state
=
{
isPowerOn
:
false
,
};
getShadow
=
async
()
=>
{
const
deviceId
=
this
.
props
.
item
.
deviceId
;
await
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
};
componentDidMount
=
async
()
=>
{
await
this
.
getShadow
();
console
.
log
(
'meter props'
,
this
.
props
);
};
componentDidUpdate
=
async
(
prevProps
,
prevState
)
=>
{
if
(
prevProps
.
shadow
!==
this
.
props
.
shadow
)
{
await
this
.
setInitState
();
}
};
setInitState
=
async
()
=>
{
const
{
shadow
}
=
this
.
props
;
this
.
setState
({
isPowerOn
:
shadow
.
SM1
.
BK_S
,
});
};
render
()
{
const
item
=
this
.
props
.
item
;
const
{
isPowerOn
}
=
this
.
state
;
return
Platform
.
OS
===
'android'
?
(
<
BaseButton
onPress
=
{
this
.
props
.
onPressEachCard
}
rippleColor
=
{
'#fcc5c5'
}
style
=
{
styles
.
cardContainer
}
>
<
View
accessible
style
=
{[
styles
.
meterOn
,
{
backgroundColor
:
i
tem
.
isOn
?
'rgba(65, 204, 0, 0.59)'
:
'rgba(223, 0, 0, 0.59)'
},
{
backgroundColor
:
i
sPowerOn
===
1
?
'rgba(65, 204, 0, 0.59)'
:
'rgba(223, 0, 0, 0.59)'
},
]}
>
<
Text
style
=
{[
theme
.
smDescription
,
theme
.
textWhite
]}
>
{
i
tem
.
isOn
?
'ON'
:
'OFF'
}
<
/Text
>
<
Text
style
=
{[
theme
.
smDescription
,
theme
.
textWhite
]}
>
{
i
sPowerOn
===
1
?
'ON'
:
'OFF'
}
<
/Text
>
<
/View
>
<
View
style
=
{[
theme
.
centerContainer
]}
>
{
item
.
img
?
(
...
...
@@ -54,10 +79,10 @@ class MeterCard extends Component {
<
View
style
=
{[
styles
.
meterOn
,
{
backgroundColor
:
i
tem
.
isOn
?
'rgba(65, 204, 0, 0.59)'
:
'rgba(223, 0, 0, 0.59)'
},
{
backgroundColor
:
i
sPowerOn
===
1
?
'rgba(65, 204, 0, 0.59)'
:
'rgba(223, 0, 0, 0.59)'
},
]}
>
<
Text
style
=
{[
theme
.
smDescription
,
theme
.
textWhite
]}
>
{
i
tem
.
isOn
?
'ON'
:
'OFF'
}
<
/Text
>
<
Text
style
=
{[
theme
.
smDescription
,
theme
.
textWhite
]}
>
{
i
sPowerOn
===
1
?
'ON'
:
'OFF'
}
<
/Text
>
<
/View
>
<
View
style
=
{[
theme
.
centerContainer
]}
>
{
item
.
img
?
(
...
...
@@ -98,7 +123,18 @@ class MeterCard extends Component {
);
}
}
export
default
MeterCard
;
const
mapStateToProps
=
state
=>
({
shadow
:
state
.
currentSelectedDeviceReducer
.
shadow
,
});
const
mapDispatchToProps
=
{
getCurrentSelectedShadow
,
};
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
MeterCard
);
const
styles
=
StyleSheet
.
create
({
meterOn
:
{
...
...
reduxStore/actions/currentSelectedAction.js
View file @
41de80af
...
...
@@ -30,12 +30,8 @@ export const getCurrentSelectedShadowAction = 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
}
`
;
export
const
getCurrentSelectedShadow
=
deviceId
=>
async
dispatch
=>
{
const
URL
=
`
${
baseURL
}
/shadow/
${
deviceId
}
`
;
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
options
=
{
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
...
...
@@ -48,39 +44,22 @@ export const getCurrentSelectedShadow = deviceId => async (dispatch, getState) =
},
}
=
await
axios
(
options
);
dispatch
(
getCurrentSelectedShadowAction
(
value
||
null
));
await
dispatch
(
getCurrentSelectedShadowAction
(
value
||
null
));
}
catch
(
error
)
{
dispatch
(
errorAction
(
error
.
message
||
error
||
'Error'
));
}
};
export
const
getCurrentSelectedData
=
deviceId
=>
async
dispatch
=>
{
const
URL
=
`
${
baseURL
}
/shadow/
${
deviceId
}
`
;
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
options
=
{
headers
:
{
Authorization
:
`Token
${
idToken
}
`
},
url
:
URL
,
};
try
{
//FIRESTORE
dispatch
(
loadingAction
(
true
));
const
currentSelectedDevice
=
await
fireStore
.
collection
(
'device'
)
.
doc
(
deviceId
)
.
get
();
const
currentSelectedDeviceData
=
await
currentSelectedDevice
.
data
();
const
currentSelectedDeviceDataMoreInfo
=
{
...
currentSelectedDeviceData
,
deviceId
:
currentSelectedDevice
.
id
};
//CLOUD FUNCTION :: GET SHADOW
const
{
data
:
{
shadow
:
{
value
},
},
}
=
await
axios
(
options
);
dispatch
(
getCurrentSelectedShadowAction
(
value
||
null
));
dispatch
(
getCurrentSelectedDataAction
(
currentSelectedDeviceDataMoreInfo
));
dispatch
(
loadingAction
(
false
));
}
catch
(
error
)
{
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
41de80af
...
...
@@ -6,7 +6,7 @@ import { TouchableOpacity } from 'react-native-gesture-handler';
import
{
connect
}
from
'react-redux'
;
import
{
getCurrentSelectedData
,
//
getCurrentSelectedShadow,
getCurrentSelectedShadow
,
loadingAction
,
setMainStatus
,
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
...
...
@@ -55,6 +55,7 @@ class SmartMeterDetailScreen extends Component {
const
deviceId
=
this
.
props
.
navigation
.
getParam
(
'deviceId'
);
await
this
.
props
.
getCurrentSelectedData
(
deviceId
);
await
this
.
props
.
getTimers
();
await
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
};
componentDidMount
=
async
()
=>
{
...
...
@@ -77,6 +78,20 @@ class SmartMeterDetailScreen extends Component {
this
.
setSubBreakersState
();
}
};
handleToggle
=
value
=>
{
const
deviceId
=
this
.
props
.
navigation
.
getParam
(
'deviceId'
);
this
.
props
.
setMainStatus
(
value
);
let
test
=
setInterval
(()
=>
{
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
console
.
log
(
'getShadow'
);
},
2000
);
console
.
log
(
'handle'
);
setTimeout
(()
=>
{
clearInterval
(
test
);
console
.
log
(
'stop checking'
);
},
6000
);
};
componentWillUnmount
=
()
=>
{
this
.
_mcbLinksListMounted
=
false
;
...
...
@@ -116,8 +131,8 @@ class SmartMeterDetailScreen extends Component {
<
/Left
>
<
Right
>
<
Switch
value
=
{
this
.
props
.
shadow
?
(
this
.
props
.
shadow
.
SM1
.
BK_S
===
1
?
true
:
false
)
:
false
}
onValueChange
=
{
value
=>
this
.
props
.
setMainStatus
(
value
)}
value
=
{
isPowerOn
===
1
?
true
:
false
}
onValueChange
=
{
value
=>
this
.
handleToggle
(
value
)}
/
>
<
/Right
>
<
/Row
>
...
...
@@ -340,7 +355,7 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
{
getCurrentSelectedData
,
//
getCurrentSelectedShadow,
getCurrentSelectedShadow
,
loadingAction
,
loadingTimersAction
,
getTimers
,
...
...
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