Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
f564eab7
Commit
f564eab7
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Save temp reminder settings
parent
de858fe8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/settings.js
+53
-26
53 additions, 26 deletions
components/settings.js
local-storage/index.js
+17
-8
17 additions, 8 deletions
local-storage/index.js
with
70 additions
and
34 deletions
components/settings.js
+
53
−
26
View file @
f564eab7
...
...
@@ -17,7 +17,12 @@ import config from '../config'
import
{
settings
as
settingsLabels
,
shared
as
sharedLabels
}
from
'
./labels
'
import
getDataAsCsvDataUri
from
'
../lib/import-export/export-to-csv
'
import
importCsv
from
'
../lib/import-export/import-from-csv
'
import
{
scaleObservable
,
saveTempScale
}
from
'
../local-storage
'
import
{
scaleObservable
,
saveTempScale
,
tempReminderObservable
,
saveTempReminder
}
from
'
../local-storage
'
export
default
class
Settings
extends
Component
{
constructor
(
props
)
{
...
...
@@ -35,31 +40,7 @@ export default class Settings extends Component {
<
Text
style
=
{
styles
.
settingsSegmentTitle
}
>
{
settingsLabels
.
tempReminder
.
title
}
<
/Text
>
<
View
style
=
{{
flexDirection
:
'
row
'
,
alignItems
:
'
center
'
}}
>
<
View
style
=
{{
flex
:
1
}}
>
{
this
.
state
.
time
?
<
Text
>
{
settingsLabels
.
tempReminder
.
timeSet
(
this
.
state
.
time
)}
<
/Text
>
:
<
Text
>
{
settingsLabels
.
tempReminder
.
noTimeSet
}
<
/Text
>
}
<
/View
>
<
Switch
value
=
{
this
.
state
.
tempReminderEnabled
}
onValueChange
=
{
val
=>
this
.
setState
({
tempReminderEnabled
:
val
})}
onTintColor
=
{
secondaryColor
}
/
>
<
/View
>
<
DateTimePicker
mode
=
"
time
"
isVisible
=
{
this
.
state
.
isTimePickerVisible
}
onConfirm
=
{
jsDate
=>
{
this
.
setState
({
time
:
padWithZeros
(
`
${
jsDate
.
getHours
()}
:
${
jsDate
.
getMinutes
()}
`
),
isTimePickerVisible
:
false
})
}}
onCancel
=
{()
=>
this
.
setState
({
isTimePickerVisible
:
false
})}
/
>
<
TempReminderPicker
/>
<
/TouchableOpacity
>
<
View
style
=
{
styles
.
settingsSegment
}
>
<
Text
style
=
{
styles
.
settingsSegmentTitle
}
>
...
...
@@ -99,6 +80,52 @@ export default class Settings extends Component {
}
}
class
TempReminderPicker
extends
Component
{
constructor
(
props
)
{
super
(
props
)
this
.
state
=
Object
.
assign
({},
tempReminderObservable
.
value
)
}
render
()
{
return
(
<
View
style
=
{{
flexDirection
:
'
row
'
,
alignItems
:
'
center
'
}}
>
<
View
style
=
{{
flex
:
1
}}
>
{
this
.
state
.
time
&&
this
.
state
.
enabled
?
<
Text
>
{
settingsLabels
.
tempReminder
.
timeSet
(
this
.
state
.
time
)}
<
/Text
>
:
<
Text
>
{
settingsLabels
.
tempReminder
.
noTimeSet
}
<
/Text
>
}
<
/View
>
<
Switch
value
=
{
this
.
state
.
enabled
}
onValueChange
=
{
val
=>
{
this
.
setState
({
enabled
:
val
})
if
(
val
&&
!
this
.
state
.
time
)
this
.
setState
({
isTimePickerVisible
:
true
})
if
(
!
val
)
saveTempReminder
({
enabled
:
false
})
}}
onTintColor
=
{
secondaryColor
}
/
>
<
DateTimePicker
mode
=
"
time
"
isVisible
=
{
this
.
state
.
isTimePickerVisible
}
onConfirm
=
{
jsDate
=>
{
const
time
=
padWithZeros
(
`
${
jsDate
.
getHours
()}
:
${
jsDate
.
getMinutes
()}
`
)
this
.
setState
({
time
,
isTimePickerVisible
:
false
})
saveTempReminder
({
time
,
enabled
:
true
})
}}
onCancel
=
{()
=>
this
.
setState
({
isTimePickerVisible
:
false
})}
/
>
<
/View
>
)
}
}
class
TempSlider
extends
Component
{
constructor
(
props
)
{
super
(
props
)
...
...
This diff is collapsed.
Click to expand it.
local-storage/index.js
+
17
−
8
View file @
f564eab7
...
...
@@ -3,20 +3,25 @@ import Observable from 'obv'
import
config
from
'
../config
'
export
const
scaleObservable
=
Observable
()
setTempScaleInitially
()
setObvWithInitValue
(
'
tempScale
'
,
scaleObservable
,
{
min
:
config
.
temperatureScale
.
defaultLow
,
max
:
config
.
temperatureScale
.
defaultHigh
})
async
function
setTempScaleInitially
()
{
const
result
=
await
AsyncStorage
.
getItem
(
'
tempScale
'
)
export
const
tempReminderObservable
=
Observable
()
setObvWithInitValue
(
'
tempReminder
'
,
tempReminderObservable
,
{
enabled
:
false
})
async
function
setObvWithInitValue
(
key
,
obv
,
defaultValue
)
{
const
result
=
await
AsyncStorage
.
getItem
(
key
)
let
value
if
(
result
)
{
value
=
JSON
.
parse
(
result
)
}
else
{
value
=
{
min
:
config
.
temperatureScale
.
defaultLow
,
max
:
config
.
temperatureScale
.
defaultHigh
}
value
=
defaultValue
}
scaleObservable
.
set
(
value
)
obv
.
set
(
value
)
}
export
async
function
saveTempScale
(
scale
)
{
...
...
@@ -24,3 +29,7 @@ export async function saveTempScale(scale) {
scaleObservable
.
set
(
scale
)
}
export
async
function
saveTempReminder
(
reminder
)
{
await
AsyncStorage
.
setItem
(
'
tempReminder
'
,
JSON
.
stringify
(
reminder
))
tempReminderObservable
.
set
(
reminder
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment