Separate warning out of absolute range

This commit is contained in:
Julia Friesel
2018-08-26 19:34:52 +02:00
parent 2a07ce4ef2
commit 8a6f943e5f
5 changed files with 55 additions and 70 deletions
-48
View File
@@ -1,48 +0,0 @@
import React from 'react'
import {
View,
Button,
} from 'react-native'
import { saveSymptom } from '../../db'
const dayView = 'DayView'
export default function (showView) {
return function ({ symptom, cycleDay, saveAction, saveDisabled}) {
const buttons = [
{
title: 'Cancel',
action: () => showView(dayView)
},
{
title: 'Delete',
action: () => {
saveSymptom(symptom, cycleDay)
showView(dayView)
}
}, {
title: 'Save',
action: async () => {
await saveAction()
showView(dayView)
},
disabledCondition: saveDisabled
}
]
return buttons.map(({ title, action, disabledCondition }, i) => {
const style = { flex: 1, marginHorizontal: 10 }
if (i === 0) style.marginLeft = 0
if (i === buttons.length - 1) style.marginRight = 0
return (
<View style={style} key={i}>
<Button
onPress={action}
disabled={disabledCondition}
title={title}>
</Button>
</View >
)
})
}
}
+1
View File
@@ -29,5 +29,6 @@ export const fertilityStatus = {
export const temperature = { export const temperature = {
outOfRangeWarning: 'This temperature value is out of the current range for the temperature chart. You can change the range in the settings.', outOfRangeWarning: 'This temperature value is out of the current range for the temperature chart. You can change the range in the settings.',
outOfAbsoluteRangeWarning: 'This temperature value is too high or low to be shown on the temperature chart.',
saveAnyway: 'Save anyway' saveAnyway: 'Save anyway'
} }
@@ -8,7 +8,14 @@ import styles, {iconStyles} from '../../../styles'
export default class ActionButtonFooter extends Component { export default class ActionButtonFooter extends Component {
render() { render() {
const { symptom, cycleDay, saveAction, saveDisabled, navigate} = this.props const {
symptom,
cycleDay,
saveAction,
saveDisabled,
navigate,
autoShowDayView = true}
= this.props
const navigateToOverView = () => navigate('CycleDay', {cycleDay}) const navigateToOverView = () => navigate('CycleDay', {cycleDay})
const buttons = [ const buttons = [
{ {
@@ -28,7 +35,7 @@ export default class ActionButtonFooter extends Component {
title: 'Save', title: 'Save',
action: () => { action: () => {
saveAction() saveAction()
navigateToOverView() if (autoShowDayView) navigateToOverView()
}, },
disabledCondition: saveDisabled, disabledCondition: saveDisabled,
icon: 'content-save-outline' icon: 'content-save-outline'
+44 -20
View File
@@ -17,6 +17,7 @@ import { temperature as tempLabels } from '../labels/labels'
import { scaleObservable } from '../../../local-storage' import { scaleObservable } from '../../../local-storage'
import { shared } from '../../labels' import { shared } from '../../labels'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
import config from '../../../config'
const minutes = ChronoUnit.MINUTES const minutes = ChronoUnit.MINUTES
@@ -49,6 +50,47 @@ export default class Temp extends Component {
} }
} }
saveTemperature = () => {
const dataToSave = {
value: Number(this.state.temperature),
exclude: this.state.exclude,
time: this.state.time
}
saveSymptom('temperature', this.cycleDay, dataToSave)
this.props.navigate('CycleDay', {cycleDay: this.cycleDay})
}
checkRangeAndSave = () => {
const value = Number(this.state.temperature)
const absolute = {
min: config.temperatureScale.min,
max: config.temperatureScale.max
}
const scale = scaleObservable.value
let warningMsg
if (value < absolute.min || value > absolute.max) {
warningMsg = tempLabels.outOfAbsoluteRangeWarning
} else if (value < scale.min || value > scale.max) {
warningMsg = tempLabels.outOfRangeWarning
}
if (warningMsg) {
Alert.alert(
shared.warning,
warningMsg,
[
{ text: shared.cancel },
{ text: shared.save, onPress: this.saveTemperature}
]
)
} else {
this.saveTemperature()
}
}
render() { render() {
return ( return (
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
@@ -98,20 +140,14 @@ export default class Temp extends Component {
<ActionButtonFooter <ActionButtonFooter
symptom='temperature' symptom='temperature'
cycleDay={this.cycleDay} cycleDay={this.cycleDay}
saveAction={() => { saveAction={() => this.checkRangeAndSave()}
const dataToSave = {
value: Number(this.state.temperature),
exclude: this.state.exclude,
time: this.state.time
}
saveSymptom('temperature', this.cycleDay, dataToSave)
}}
saveDisabled={ saveDisabled={
this.state.temperature === '' || this.state.temperature === '' ||
isNaN(Number(this.state.temperature)) || isNaN(Number(this.state.temperature)) ||
isInvalidTime(this.state.time) isInvalidTime(this.state.time)
} }
navigate={this.props.navigate} navigate={this.props.navigate}
autoShowDayView={false}
/> />
</View> </View>
) )
@@ -119,18 +155,6 @@ export default class Temp extends Component {
} }
class TempInput extends Component { class TempInput extends Component {
checkRange = () => {
const value = Number(this.props.value)
if (isNaN(value)) return
const scale = scaleObservable.value
if (value < scale.min || value > scale.max) {
Alert.alert(
shared.warning,
tempLabels.outOfRangeWarning,
)
}
}
render() { render() {
const style = [styles.temperatureTextInput] const style = [styles.temperatureTextInput]
if (this.props.isSuggestion) { if (this.props.isSuggestion) {
+1
View File
@@ -1,5 +1,6 @@
export const shared = { export const shared = {
cancel: 'Cancel', cancel: 'Cancel',
save: 'Save',
errorTitle: 'Error', errorTitle: 'Error',
successTitle: 'Success', successTitle: 'Success',
warning: 'Warning' warning: 'Warning'