diff --git a/components/cycle-day/action-buttons.js b/components/cycle-day/action-buttons.js deleted file mode 100644 index 9ddb036ede70c6849c730787408cd56b15edd7f0..0000000000000000000000000000000000000000 --- a/components/cycle-day/action-buttons.js +++ /dev/null @@ -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 > - ) - }) - } -} \ No newline at end of file diff --git a/components/cycle-day/labels/labels.js b/components/cycle-day/labels/labels.js index 910e6c96650d30472861e4372a28c617299496e7..6650e335efde0c62ad1e55ba181dd230e0db7e2f 100644 --- a/components/cycle-day/labels/labels.js +++ b/components/cycle-day/labels/labels.js @@ -29,5 +29,6 @@ export const fertilityStatus = { 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.', + outOfAbsoluteRangeWarning: 'This temperature value is too high or low to be shown on the temperature chart.', saveAnyway: 'Save anyway' } diff --git a/components/cycle-day/symptoms/action-button-footer.js b/components/cycle-day/symptoms/action-button-footer.js index a1534964ea7cfeb0b7e651bdf5c590463b098acf..dac39a6a82fa036b6a4645bcec941064c588551b 100644 --- a/components/cycle-day/symptoms/action-button-footer.js +++ b/components/cycle-day/symptoms/action-button-footer.js @@ -8,7 +8,14 @@ import styles, {iconStyles} from '../../../styles' export default class ActionButtonFooter extends Component { 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 buttons = [ { @@ -28,7 +35,7 @@ export default class ActionButtonFooter extends Component { title: 'Save', action: () => { saveAction() - navigateToOverView() + if (autoShowDayView) navigateToOverView() }, disabledCondition: saveDisabled, icon: 'content-save-outline' diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index fda52006729b9225d16ed2ec9dca7aa32e54c0fa..11ee7dae56311d64398780bde7926a7f0bb83cd4 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -17,6 +17,7 @@ import { temperature as tempLabels } from '../labels/labels' import { scaleObservable } from '../../../local-storage' import { shared } from '../../labels' import ActionButtonFooter from './action-button-footer' +import config from '../../../config' 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() { return ( <View style={{ flex: 1 }}> @@ -98,20 +140,14 @@ export default class Temp extends Component { <ActionButtonFooter symptom='temperature' cycleDay={this.cycleDay} - saveAction={() => { - const dataToSave = { - value: Number(this.state.temperature), - exclude: this.state.exclude, - time: this.state.time - } - saveSymptom('temperature', this.cycleDay, dataToSave) - }} + saveAction={() => this.checkRangeAndSave()} saveDisabled={ this.state.temperature === '' || isNaN(Number(this.state.temperature)) || isInvalidTime(this.state.time) } navigate={this.props.navigate} + autoShowDayView={false} /> </View> ) @@ -119,18 +155,6 @@ export default class Temp 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() { const style = [styles.temperatureTextInput] if (this.props.isSuggestion) { diff --git a/components/labels.js b/components/labels.js index 28cd39392118a8faf8aef9a394d7b991e796f992..b249e37876279b3cf763bdaf6f336b180bc17d4f 100644 --- a/components/labels.js +++ b/components/labels.js @@ -1,5 +1,6 @@ export const shared = { cancel: 'Cancel', + save: 'Save', errorTitle: 'Error', successTitle: 'Success', warning: 'Warning'