From e3ddcaa0b1a417cb40ac0765197f059b8a9c8da5 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Mon, 16 Jul 2018 18:54:09 +0200 Subject: [PATCH 1/4] Save time when first entering temp --- components/cycle-day/symptoms/temperature.js | 18 ++++++++++++++++-- db.js | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index b9a3d5b..07761df 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -27,7 +27,8 @@ export default class Temp extends Component { this.state = { currentValue: initialValue, - exclude: this.cycleDay.temperature ? this.cycleDay.temperature.exclude : false + exclude: this.cycleDay.temperature ? this.cycleDay.temperature.exclude : false, + time: this.cycleDay.temperature ? this.cycleDay.temperature.time : null } } @@ -47,6 +48,17 @@ export default class Temp extends Component { value={this.state.currentValue} /> + + Time + { + this.setState({ time: val }) + }} + keyboardType='numeric' + value={this.state.time} + /> + Exclude { const dataToSave = { value: Number(this.state.currentValue), - exclude: this.state.exclude + exclude: this.state.exclude, + time: this.state.time || + LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString() } if (!cycleDay.temperature || cycleDay.temperature && !cycleDay.temperature.time) { const now = LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString() diff --git a/db.js b/db.js index c0533bf..e2cf940 100644 --- a/db.js +++ b/db.js @@ -6,7 +6,11 @@ const TemperatureSchema = { name: 'Temperature', properties: { value: 'double', - exclude: 'bool' + exclude: 'bool', + time: { + type: 'string', + optional: true + }, } } From ce87dda091c1b0612921d6bec78653afbbd7e0fa Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Mon, 16 Jul 2018 19:01:45 +0200 Subject: [PATCH 2/4] Make time field visible for new temps also --- components/cycle-day/symptoms/temperature.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index 07761df..1b77927 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -17,9 +17,11 @@ export default class Temp extends Component { this.makeActionButtons = props.makeActionButtons let initialValue - if (this.cycleDay.temperature) { - initialValue = this.cycleDay.temperature.value.toString() - this.time = this.cycleDay.temperature.time + const temp = this.cycleDay.temperature + + if (temp) { + initialValue = temp.value.toString() + this.time = temp.time } else { const prevTemp = getPreviousTemperature(this.cycleDay) initialValue = prevTemp ? prevTemp.toString() : '' @@ -27,8 +29,8 @@ export default class Temp extends Component { this.state = { currentValue: initialValue, - exclude: this.cycleDay.temperature ? this.cycleDay.temperature.exclude : false, - time: this.cycleDay.temperature ? this.cycleDay.temperature.time : null + exclude: temp ? temp.exclude : false, + time: this.time || LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString() } } @@ -48,7 +50,7 @@ export default class Temp extends Component { value={this.state.currentValue} /> - + Time Date: Wed, 18 Jul 2018 16:51:49 +0200 Subject: [PATCH 3/4] Only activate save button when time is a valid one --- components/cycle-day/symptoms/temperature.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index 1b77927..694c8b3 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -80,16 +80,21 @@ export default class Temp extends Component { exclude: this.state.exclude, time: this.state.time } - if (!cycleDay.temperature || cycleDay.temperature && !cycleDay.temperature.time) { - const now = LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString() - dataToSave.time = now - } saveSymptom('temperature', cycleDay, dataToSave) }, - saveDisabled: this.state.currentValue === '' + saveDisabled: this.state.currentValue === '' || isInvalidTime(this.state.time) })} ) } } + +function isInvalidTime(timeString) { + try { + LocalTime.parse(timeString) + } catch (err) { + return true + } + return false +} \ No newline at end of file From 44c31b197ee47e34bc4960a59228b5095c9e6a9e Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Thu, 19 Jul 2018 18:27:46 +0200 Subject: [PATCH 4/4] Use time picker for time field --- components/cycle-day/symptoms/temperature.js | 24 ++++++++-- package-lock.json | 49 ++++++++++++++++++++ package.json | 1 + 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index 694c8b3..11961a9 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -3,8 +3,10 @@ import { View, Text, TextInput, - Switch + Switch, + Keyboard } from 'react-native' +import DateTimePicker from 'react-native-modal-datetime-picker-nevo' import { getPreviousTemperature, saveSymptom } from '../../../db' import styles from '../../../styles' @@ -30,7 +32,8 @@ export default class Temp extends Component { this.state = { currentValue: initialValue, exclude: temp ? temp.exclude : false, - time: this.time || LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString() + time: this.time || LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString(), + isTimePickerVisible: false } } @@ -54,13 +57,24 @@ export default class Temp extends Component { Time { - this.setState({ time: val }) + onFocus={() => { + Keyboard.dismiss() + this.setState({isTimePickerVisible: true}) }} - keyboardType='numeric' value={this.state.time} /> + { + this.setState({ + time: `${jsDate.getHours()}:${jsDate.getMinutes()}`, + isTimePickerVisible: false + }) + }} + onCancel={() => this.setState({isTimePickerVisible: false})} + /> Exclude