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
e57d12e6
Commit
e57d12e6
authored
Aug 29, 2019
by
Tonk
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'injectedFirebase' into ejectedExpo
parents
bffba9d9
1f37ed1b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
103 deletions
+95
-103
components/MeterCard.js
+44
-43
reduxStore/actions/timersAction.js
+7
-4
reduxStore/reducers/timersReducer.js
+9
-12
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+13
-7
screens/Private/SmartMeterScreen/SmartMeterScreen.js
+10
-28
screens/Private/TimerScreen/TimerScreen.andriod.js
+12
-9
No files found.
components/MeterCard.js
View file @
e57d12e6
import
React
,
{
Component
}
from
'react'
;
import
{
Card
,
View
,
Row
,
Icon
,
Text
}
from
'native-base'
;
import
{
Image
,
TouchableOpacity
,
StyleSheet
}
from
'react-native'
;
import
{
Image
,
StyleSheet
}
from
'react-native'
;
import
{
RectButton
}
from
'react-native-gesture-handler'
;
import
{
color
,
theme
}
from
'../constants/Styles'
;
const
styles
=
StyleSheet
.
create
({
meterOn
:
{
top
:
7
,
left
:
5
,
width
:
35
,
paddingVertical
:
1
,
borderRadius
:
9.6
,
position
:
'absolute'
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
},
meterImgStyle
:
{
width
:
50
,
height
:
80
,
resizeMode
:
'contain'
,
},
online
:
{
top
:
27
,
left
:
0
,
width
:
8
,
height
:
8
,
borderRadius
:
10
,
position
:
'absolute'
,
backgroundColor
:
color
.
statusOn
,
},
meterIconCover
:
{
width
:
32
,
height
:
32
,
marginRight
:
20
,
borderRadius
:
100
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
backgroundColor
:
color
.
defaultBg
,
},
meterIconStyle
:
{
fontSize
:
15
,
color
:
color
.
grey
,
},
});
class
MeterCard
extends
Component
{
render
()
{
return
(
<
TouchableOpacity
onPress
=
{
this
.
props
.
onPressEachCard
}
>
<
RectButton
onPress
=
{
this
.
props
.
onPressEachCard
}
>
<
Card
style
=
{[
theme
.
rowContainer
,
{
borderRadius
:
8
,
marginBottom
:
10
,
height
:
136
}]}
>
<
View
style
=
{[
...
...
@@ -89,8 +50,48 @@ class MeterCard extends Component {
<
/Row
>
<
/View
>
<
/Card
>
<
/
TouchableOpacity
>
<
/
RectButton
>
);
}
}
export
default
MeterCard
;
const
styles
=
StyleSheet
.
create
({
meterOn
:
{
top
:
7
,
left
:
5
,
width
:
35
,
paddingVertical
:
1
,
borderRadius
:
9.6
,
position
:
'absolute'
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
},
meterImgStyle
:
{
width
:
50
,
height
:
80
,
resizeMode
:
'contain'
,
},
online
:
{
top
:
27
,
left
:
0
,
width
:
8
,
height
:
8
,
borderRadius
:
10
,
position
:
'absolute'
,
backgroundColor
:
color
.
statusOn
,
},
meterIconCover
:
{
width
:
32
,
height
:
32
,
marginRight
:
20
,
borderRadius
:
100
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
backgroundColor
:
color
.
defaultBg
,
},
meterIconStyle
:
{
fontSize
:
15
,
color
:
color
.
grey
,
},
});
reduxStore/actions/timersAction.js
View file @
e57d12e6
...
...
@@ -123,7 +123,10 @@ export const getTimers = () => async (dispatch, getState) => {
existedSubBreakers
.
push
(
selectedDeviceSubBreakersDetails
.
docs
.
map
(
subBreaker
=>
Object
.
assign
(
subBreaker
.
data
(),
{
mcbLinkId
:
mcbLink
.
id
,
subBreakerId
:
subBreaker
.
id
})
Object
.
assign
(
// subBreaker.data(),
{
mcbLinkId
:
mcbLink
.
id
,
subBreakerId
:
subBreaker
.
id
}
)
)
);
...
...
@@ -163,8 +166,8 @@ export const getTimers = () => async (dispatch, getState) => {
dispatch
(
getExistedDataAction
(
existedSubBreakers
));
dispatch
(
getMainDeviceTImersAction
(
mainDeviceTimers
));
dispatch
(
getSubBreakersTimersAction
(
subBreakersTimers
));
//
dispatch(getMainDeviceTImersAction(mainDeviceTimers));
//
dispatch(getSubBreakersTimersAction(subBreakersTimers));
allTimersData
=
[...
mainDeviceTimers
,
...
subBreakersTimers
];
dispatch
(
getTimersAction
(
allTimersData
));
...
...
@@ -209,7 +212,7 @@ export const createNewTimer = (mcbLinkId, subBreakerId, settingTime) => async (d
await
docRef
.
add
(
settingTime
);
return
true
;
}
else
{
alert
(
'
This
Breaker cannot have more than 5 timers.'
);
alert
(
'Breaker cannot have more than 5 timers.'
);
return
false
;
}
}
catch
(
e
)
{
...
...
reduxStore/reducers/timersReducer.js
View file @
e57d12e6
...
...
@@ -3,23 +3,21 @@ import {
GET_TIMERS_LOADING
,
GET_TIMERS_ERROR
,
GET_EXISTED_DATA
,
GET_MAIN_DEVICE_TIMERS
,
GET_SUBBREAKERS_TIMERS
,
GET_SELECTED_TIMER_DATA
,
SET_EDIT_MODAL_VISIBLE
,
// GET_MCBLINKS_TIMERS,
// GET_MAIN_DEVICE_TIMERS,
// GET_SUBBREAKERS_TIMERS,
}
from
'../actions/timersAction'
;
const
initState
=
{
allTimers
:
[],
mainDeviceTimers
:
[],
subBreakersTimers
:
[],
existedData
:
{},
selectedTimerData
:
null
,
isEditVisible
:
false
,
isLoading
:
true
,
error
:
null
,
// mcbLinksTimers: [],
// mainDeviceTimers: [],
// subBreakersTimers: [],
};
const
timersReducer
=
(
state
=
initState
,
action
)
=>
{
...
...
@@ -28,10 +26,6 @@ const timersReducer = (state = initState, action) => {
return
{
...
state
,
existedData
:
action
.
existedData
};
case
GET_TIMERS
:
return
{
...
state
,
allTimers
:
action
.
allTimers
};
case
GET_MAIN_DEVICE_TIMERS
:
return
{
...
state
,
mainDeviceTimers
:
action
.
mainDeviceTimers
};
case
GET_SUBBREAKERS_TIMERS
:
return
{
...
state
,
subBreakersTimers
:
action
.
subBreakersTimers
};
case
GET_SELECTED_TIMER_DATA
:
return
{
...
state
,
selectedTimerData
:
action
.
selectedTimerData
};
case
SET_EDIT_MODAL_VISIBLE
:
...
...
@@ -40,8 +34,11 @@ const timersReducer = (state = initState, action) => {
return
{
...
state
,
isLoading
:
action
.
isLoading
};
case
GET_TIMERS_ERROR
:
return
{
...
state
,
error
:
action
.
error
};
// case GET_MCBLINKS_TIMERS:
// return { ...state, mcbLinksTimers: action.mcbLinksTimers };
// case GET_MAIN_DEVICE_TIMERS:
// return { ...state, mainDeviceTimers: action.mainDeviceTimers };
// case GET_SUBBREAKERS_TIMERS:
// return { ...state, subBreakersTimers: action.subBreakersTimers };
default
:
return
state
;
}
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
e57d12e6
...
...
@@ -4,9 +4,7 @@ import { color, theme } from '../../../constants/Styles';
import
{
FlatList
,
StyleSheet
}
from
'react-native'
;
import
{
TouchableOpacity
}
from
'react-native-gesture-handler'
;
import
{
connect
}
from
'react-redux'
;
import
{
fireStore
}
from
'../../../firebase'
;
import
firebase
from
'firebase/app'
;
import
'firebase/firestore'
;
import
{
setCurrentSelected
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
// Main Breaker mock data
const
MainBreaker
=
{
name
:
'Main Breaker'
,
...
...
@@ -106,9 +104,10 @@ class SmartMeterDetailScreen extends Component {
sb
:
this
.
expandState
(),
data
:
this
.
props
.
allMainDeviceInfo
.
find
(
x
=>
x
.
deviceId
===
this
.
props
.
selectedDeviceId
),
};
componentDidMount
()
{
console
.
log
(
'state'
,
this
.
state
);
console
.
log
(
'props'
,
this
.
props
);
constructor
(
props
)
{
super
(
props
);
this
.
props
.
setCurrentSelected
(
this
.
props
.
navigation
.
getParam
(
'deviceId'
));
}
renderCurrent
(
item
,
index
)
{
return
(
...
...
@@ -283,7 +282,14 @@ const mapStateToProps = state => ({
selectedDeviceId
:
state
.
currentSelectedDeviceReducer
.
selectedDeviceId
,
});
export
default
connect
(
mapStateToProps
)(
SmartMeterDetailScreen
);
const
mapDispatchToProps
=
{
setCurrentSelected
,
};
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
SmartMeterDetailScreen
);
const
styles
=
StyleSheet
.
create
({
currentCard
:
{
flex
:
1
,
...
...
screens/Private/SmartMeterScreen/SmartMeterScreen.js
View file @
e57d12e6
...
...
@@ -46,10 +46,13 @@ class SmartMeterScreen extends PureComponent {
description
=
{
item
.
description
||
''
}
img
=
{
item
.
img
||
null
}
isOnline
=
{
item
.
isOnline
||
false
}
isOn
=
{
item
.
switch
||
false
}
onPressEachCard
=
{
async
()
=>
{
await
this
.
props
.
setCurrentSelected
(
item
.
deviceId
);
this
.
props
.
navigation
.
navigate
(
'SmartMeterDetail'
,
{
name
:
item
.
name
||
''
});
isOn
=
{
item
.
isOn
||
false
}
onPressEachCard
=
{()
=>
{
// this.props.setCurrentSelected(item.deviceId);
this
.
props
.
navigation
.
navigate
(
'SmartMeterDetail'
,
{
name
:
item
.
name
||
''
,
deviceId
:
item
.
deviceId
,
});
}}
/
>
);
...
...
@@ -70,35 +73,15 @@ class SmartMeterScreen extends PureComponent {
const
{
allMainDeviceInfo
,
isLoading
,
error
}
=
this
.
props
;
return
!
error
?
(
<>
<
View
style
=
{{
padding
:
15
,
flexDirection
:
'row'
,
alignItems
:
'center'
,
backgroundColor
:
color
.
defaultBg
,
}}
>
<
SearchBar
containerStyle
=
{
styles
.
searchBarContainer
}
inputContainerStyle
=
{
styles
.
searchBarInputContainer
}
inputStyle
=
{
styles
.
searchBarInput
}
round
lightTheme
placeholder
=
"Search..."
onChangeText
=
{
text
=>
this
.
updateSearch
(
text
)}
value
=
{
this
.
state
.
search
}
/
>
<
/View
>
<
FlatList
removeClippedSubviews
=
{
tru
e
}
removeClippedSubviews
=
{
fals
e
}
refreshing
=
{
isLoading
}
onRefresh
=
{
this
.
getData
}
style
=
{[
theme
.
container
,
theme
.
containerWithPadding
]}
contentContainerStyle
=
{{
paddingBottom
:
isIphoneX
()
?
90
:
55
}}
//iPhoneX BottomSpace = 34
data
=
{
allMainDeviceInfo
}
extraData
=
{
allMainDeviceInfo
}
keyExtractor
=
{(
item
,
index
)
=>
`Card
${
item
.
deviceId
}
`
}
// extraData={this.props
}
keyExtractor
=
{(
item
,
index
)
=>
item
.
deviceId
}
ListEmptyComponent
=
{()
=>
(
<
View
>
<
Text
style
=
{[
theme
.
normalText
,
{
marginTop
:
20
}]}
>
...
...
@@ -111,7 +94,6 @@ class SmartMeterScreen extends PureComponent {
)}
renderItem
=
{
this
.
renderItem
}
/
>
<
/
>
)
:
(
<
View
>
<
Text
>
{
error
}
<
/Text
>
...
...
screens/Private/TimerScreen/TimerScreen.andriod.js
View file @
e57d12e6
...
...
@@ -38,9 +38,9 @@ initTime.setDate(0);
initTime
.
setSeconds
(
0
);
const
initTimeSetting
=
{
mcbLinkId
:
null
,
i
d
:
null
,
key
:
null
,
//
mcbLinkId: null,
// subBreakerI
d: null,
//
key: null,
isActive
:
false
,
isPowerOn
:
false
,
timer
:
initTime
,
...
...
@@ -60,7 +60,6 @@ const initState = {
isAddVisible
:
false
,
isfilterVisible
:
false
,
checked
:
[],
search
:
''
,
selectedBreaker
:
null
,
//Main or mcbLink
...
...
@@ -84,6 +83,11 @@ class TimerScreen extends PureComponent {
subBreakerList
:
[],
};
constructor
(
props
)
{
super
(
props
);
this
.
props
.
getTimers
();
}
setPickerSelectData
=
()
=>
{
let
pickerSelectData
=
[{
label
:
'Main Device'
,
value
:
'main'
}];
...
...
@@ -158,15 +162,15 @@ class TimerScreen extends PureComponent {
const
isCreated
=
await
this
.
props
.
createNewTimer
(
null
,
null
,
timerData
);
if
(
isCreated
)
{
this
.
props
.
getTimers
();
this
.
resetStateAndProps
();
this
.
props
.
getTimers
();
}
}
else
if
(
selectedBreaker
&&
selectedSubBreaker
)
{
await
this
.
props
.
createNewTimer
(
selectedBreaker
,
selectedSubBreaker
.
id
,
timerData
);
this
.
resetStateAndProps
();
this
.
props
.
getTimers
();
}
else
{
alert
(
'please select
Sub
Breaker'
);
alert
(
'please select
(Sub)
Breaker'
);
}
}
else
if
(
isEditVisible
)
{
this
.
props
.
editTimer
(
timerData
);
...
...
@@ -214,7 +218,6 @@ class TimerScreen extends PureComponent {
<
/TouchableOpacity
>
),
});
this
.
props
.
getTimers
();
// this.setExistedSubBreaker();
// this.props.existedData && this.setPickerSelectData();
console
.
log
(
'STATE'
,
this
.
state
);
...
...
@@ -422,7 +425,7 @@ class TimerScreen extends PureComponent {
<
FlatList
contentContainerStyle
=
{{
paddingBottom
:
isIphoneX
()
?
90
:
55
}}
data
=
{
this
.
props
.
allTimers
}
extraData
=
{
this
.
props
.
allTimers
}
//
extraData={this.props.allTimers}
refreshing
=
{
this
.
props
.
isLoading
}
onRefresh
=
{
this
.
props
.
getTimers
}
ListEmptyComponent
=
{()
=>
(
...
...
@@ -434,7 +437,7 @@ class TimerScreen extends PureComponent {
renderItem
=
{({
item
,
index
})
=>
(
<
SwipeableRow
item
=
{
item
}
index
=
{
index
}
onSwipeOpen
=
{
this
.
autoCloseSwipeRow
}
/
>
)}
keyExtractor
=
{(
item
,
index
)
=>
`timer
${
i
ndex
}
`
}
keyExtractor
=
{(
item
,
index
)
=>
`timer
${
i
tem
.
key
}
`
}
/
>
{
/* Create & Update Timer Modal */
}
...
...
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