From 018ec3bcda56d0dd83a2c6c359bfdae4749cedd3 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Sun, 26 May 2019 09:04:51 +0200 Subject: [PATCH] Add autosave for temperate --- components/cycle-day/symptoms/temperature.js | 27 ++++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index 8171f86..ff445ce 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -63,19 +63,12 @@ export default class Temp extends SymptomView { }) } - async onBackButtonPress() { + autoSave = () => { if (typeof this.state.temperature != 'string' || this.state.temperature === '') { this.deleteSymptomEntry() return } - const userWantsToSave = await this.warnUserIfTempOutOfRange() - if (!userWantsToSave) return true - - this.saveTemperature() - } - - saveTemperature = () => { const dataToSave = { value: Number(this.state.temperature), exclude: this.state.exclude, @@ -103,15 +96,14 @@ export default class Temp extends SymptomView { // it in a promise return new Promise(resolve => { if (warningMsg) { + // we set this so the time picker doesn't open at the same time + this.warningAlertOpen = true Alert.alert( sharedLabels.warning, warningMsg, [ - { text: sharedLabels.cancel, onPress: () => { - resolve(false) - }}, - { text: sharedLabels.save, onPress: () => { - resolve(true) + { text: sharedLabels.ok, onPress: () => { + this.warningAlertOpen = false }} ] ) @@ -154,6 +146,7 @@ export default class Temp extends SymptomView { onChangeText={this.setTemperature} keyboardType='numeric' maxLength={5} + onBlur={this.warnUserIfTempOutOfRange} /> °C @@ -164,7 +157,13 @@ export default class Temp extends SymptomView { { + if (this.warningAlertOpen) { + Keyboard.dismiss() + } else { + this.showTimePicker() + } + }} value={this.state.time} />