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
3557838e
Commit
3557838e
authored
Sep 02, 2019
by
Tonk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update setting screen
parent
d7177405
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
6 deletions
+88
-6
reduxStore/actions/currentSelectedAction.js
+35
-1
screens/Private/SettingScreen/Setting.js
+17
-2
screens/Private/SettingScreen/SettingScreen.js
+36
-3
No files found.
reduxStore/actions/currentSelectedAction.js
View file @
3557838e
//
import { fireStore } from '../../firebase';
import
{
fireStore
}
from
'../../firebase'
;
// export const SET_CURRENT_SELECTED = 'SET_CURRENT_SELECTED';
export
const
GET_CURRENT_SELECTED_DATA
=
'GET_CURRENT_SELECTED_DATA'
;
...
...
@@ -21,6 +21,40 @@ export const getCurrentSelectedData = currentSelectedDeviceData => dispatch => {
dispatch
(
getCurrentSelectedDataAction
(
currentSelectedDeviceData
));
};
export
const
updateDetail
=
(
type
,
value
)
=>
async
(
dispatch
,
getState
)
=>
{
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
getNewData
=
()
=>
{
switch
(
type
)
{
case
'Name'
:
return
{
...
currentSelectedData
,
name
:
value
};
case
'Description'
:
return
{
...
currentSelectedData
,
description
:
value
};
case
'RCBO'
:
return
{
...
currentSelectedData
,
rcbo
:
value
};
case
'notification'
:
return
{
...
currentSelectedData
,
notification
:
value
};
default
:
return
currentSelectedData
;
}
};
const
getRef
=
()
=>
{
const
ref
=
fireStore
.
collection
(
'device'
).
doc
(
selectedDeviceId
);
return
ref
;
};
try
{
const
newData
=
getNewData
();
dispatch
(
getCurrentSelectedData
(
newData
));
const
ref
=
getRef
();
await
ref
.
update
(
newData
);
}
catch
(
e
)
{
alert
(
e
);
}
};
// export const getCurrentSelectedData = (deviceId, mcbLinkId, subBreakerId) => (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
...
...
screens/Private/SettingScreen/Setting.js
View file @
3557838e
...
...
@@ -6,8 +6,10 @@ import { HeaderButtons, Item } from 'react-navigation-header-buttons';
import
IoniconsHeaderButton
from
'../../../components/IoniconsHeaderButton'
;
import
{
width
}
from
'../../../constants/Layout'
;
import
{
Overlay
}
from
'react-native-elements'
;
import
{
connect
}
from
'react-redux'
;
import
{
updateDetail
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
export
default
class
SmartMeter
DetailScreen
extends
Component
{
class
update
DetailScreen
extends
Component
{
static
navigationOptions
=
({
navigation
})
=>
{
return
{
title
:
'Setting'
,
...
...
@@ -31,6 +33,10 @@ export default class SmartMeterDetailScreen extends Component {
isVisible
:
visible
,
});
}
confirm
()
{
this
.
props
.
updateDetail
(
this
.
state
.
field
,
this
.
state
.
data
);
this
.
props
.
navigation
.
navigate
(
'Setting'
);
}
render
()
{
const
{
breaker
,
data
,
field
,
isVisible
}
=
this
.
state
;
return
(
...
...
@@ -100,7 +106,7 @@ export default class SmartMeterDetailScreen extends Component {
>
<
Text
style
=
{{
color
:
color
.
grey
}}
>
CANCEL
<
/Text
>
<
/Button
>
<
Button
style
=
{
styles
.
saveBtn
}
onPress
=
{
this
.
save
}
rounded
>
<
Button
style
=
{
styles
.
saveBtn
}
rounded
onPress
=
{()
=>
this
.
confirm
()}
>
<
Text
>
SAVE
<
/Text
>
<
/Button
>
<
/View
>
...
...
@@ -111,6 +117,15 @@ export default class SmartMeterDetailScreen extends Component {
}
}
const
mapDispatchToProps
=
{
updateDetail
,
};
export
default
connect
(
null
,
mapDispatchToProps
)(
updateDetailScreen
);
const
styles
=
StyleSheet
.
create
({
overlayStyle
:
{
padding
:
20
,
...
...
screens/Private/SettingScreen/SettingScreen.js
View file @
3557838e
...
...
@@ -5,6 +5,7 @@ import { theme, color } from '../../../constants/Styles';
import
{
connect
}
from
'react-redux'
;
import
{
Overlay
}
from
'react-native-elements'
;
import
{
TouchableHighlight
}
from
'react-native-gesture-handler'
;
import
{
updateDetail
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
class
SettingScreen
extends
React
.
Component
{
static
navigationOptions
=
({
navigation
})
=>
({
...
...
@@ -31,11 +32,23 @@ class SettingScreen extends React.Component {
});
}
state
=
{
data
:
this
.
props
.
allMainDeviceInfo
.
find
(
x
=>
x
.
deviceId
===
this
.
props
.
currentSelectedData
.
deviceId
)
,
data
:
''
,
isVisible
:
false
,
pressQr
:
false
,
pressMail
:
false
,
};
componentDidMount
()
{
this
.
setState
({
data
:
this
.
props
.
currentSelectedData
,
});
}
componentDidUpdate
(
prevProps
,
prevState
)
{
if
(
prevProps
.
currentSelectedData
!=
this
.
props
.
currentSelectedData
)
{
this
.
setState
({
data
:
this
.
props
.
currentSelectedData
,
});
}
}
toggleModal
(
visible
)
{
this
.
setState
({
isVisible
:
visible
,
...
...
@@ -110,12 +123,26 @@ class SettingScreen extends React.Component {
<
Icon
name
=
"arrow-forward"
/>
<
/Right
>
<
/ListItem
>
<
ListItem
style
=
{{
borderBottomColor
:
'#efefef'
}}
>
<
Body
>
<
Text
style
=
{[
theme
.
normalText
,
theme
.
textDark
]}
>
WiFi
<
/Text
>
<
Text
note
numberOfLines
=
{
1
}
style
=
{
theme
.
description
}
>
...
<
/Text
>
<
/Body
>
<
Right
>
<
Icon
name
=
"arrow-forward"
/>
<
/Right
>
<
/ListItem
>
<
ListItem
style
=
{{
borderBottomWidth
:
0
}}
>
<
Body
>
<
Text
style
=
{[
theme
.
normalText
,
theme
.
textDark
]}
>
Notification
<
/Text
>
<
/Body
>
<
Right
>
<
Switch
value
=
{
data
.
notification
}
/
>
<
Switch
value
=
{
data
.
notification
}
onValueChange
=
{
value
=>
this
.
props
.
updateDetail
(
'notification'
,
value
)}
/
>
<
/Right
>
<
/ListItem
>
<
/List
>
...
...
@@ -201,8 +228,14 @@ const mapStateToProps = state => ({
allMainDeviceInfo
:
state
.
allMainDeviceReducer
.
allMainDeviceInfo
,
currentSelectedData
:
state
.
currentSelectedDeviceReducer
.
currentSelectedData
,
});
const
mapDispatchToProps
=
{
updateDetail
,
};
export
default
connect
(
mapStateToProps
)(
SettingScreen
);
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
SettingScreen
);
const
styles
=
StyleSheet
.
create
({
ListItemContainer
:
{
...
...
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