Skip to content
Snippets Groups Projects
Commit 0e77a2f6 authored by Julia Friesel's avatar Julia Friesel
Browse files

Re-simplify the input

parent eedd6070
No related branches found
No related tags found
No related merge requests found
...@@ -30,21 +30,19 @@ export default class Temp extends Component { ...@@ -30,21 +30,19 @@ export default class Temp extends Component {
exclude: temp ? temp.exclude : false, exclude: temp ? temp.exclude : false,
time: temp ? temp.time : LocalTime.now().truncatedTo(minutes).toString(), time: temp ? temp.time : LocalTime.now().truncatedTo(minutes).toString(),
isTimePickerVisible: false, isTimePickerVisible: false,
integer: '',
fractional: '',
outOfRange: null outOfRange: null
} }
if (temp) { if (temp) {
const [integer, fractional] = temp.value.toString().split('.') this.state.temperature = temp.value.toString()
this.state.integer = integer if (temp.value === Math.floor(temp.value)) {
this.state.fractional = fractional || '0' this.state.temperature = `${this.state.temperature}.0`
}
} else { } else {
const prevTemp = getPreviousTemperature(this.cycleDay) const prevTemp = getPreviousTemperature(this.cycleDay)
console.log(prevTemp)
if (prevTemp) { if (prevTemp) {
const [integer, fractional] = prevTemp.toString().split('.') this.state.temperature = prevTemp.toString()
this.state.integer = integer
this.state.fractional = fractional
this.state.isSuggestion = true this.state.isSuggestion = true
} }
} }
...@@ -55,9 +53,8 @@ export default class Temp extends Component { ...@@ -55,9 +53,8 @@ export default class Temp extends Component {
<View style={styles.symptomEditView}> <View style={styles.symptomEditView}>
<View style={styles.symptomViewRowInline}> <View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Temperature (°C)</Text> <Text style={styles.symptomDayView}>Temperature (°C)</Text>
<TempInputPair <TempInput
integer={this.state.integer} value={this.state.temperature}
fractional={this.state.fractional}
setState={(val) => this.setState(val)} setState={(val) => this.setState(val)}
isSuggestion={this.state.isSuggestion} isSuggestion={this.state.isSuggestion}
/> />
...@@ -78,7 +75,7 @@ export default class Temp extends Component { ...@@ -78,7 +75,7 @@ export default class Temp extends Component {
isVisible={this.state.isTimePickerVisible} isVisible={this.state.isTimePickerVisible}
onConfirm={jsDate => { onConfirm={jsDate => {
this.setState({ this.setState({
time: `${jsDate.getinteger()}:${jsDate.getfractional()}`, time: `${jsDate.getHours()}:${jsDate.getMinutes()}`,
isTimePickerVisible: false isTimePickerVisible: false
}) })
}} }}
...@@ -98,18 +95,16 @@ export default class Temp extends Component { ...@@ -98,18 +95,16 @@ export default class Temp extends Component {
symptom: 'temperature', symptom: 'temperature',
cycleDay: this.cycleDay, cycleDay: this.cycleDay,
saveAction: async () => { saveAction: async () => {
const v = Number(`${this.state.integer}.${this.state.fractional}`)
const dataToSave = { const dataToSave = {
value: v, value: Number(this.state.temperature),
exclude: this.state.exclude, exclude: this.state.exclude,
time: this.state.time time: this.state.time
} }
saveSymptom('temperature', this.cycleDay, dataToSave) saveSymptom('temperature', this.cycleDay, dataToSave)
}, },
saveDisabled: saveDisabled:
this.state.integer === '' || this.state.temperature === '' ||
isNaN(Number(this.state.integer)) || isNaN(Number(this.state.temperature)) ||
isNaN(Number(this.state.fractional)) ||
isInvalidTime(this.state.time) isInvalidTime(this.state.time)
})} })}
</View> </View>
...@@ -118,32 +113,10 @@ export default class Temp extends Component { ...@@ -118,32 +113,10 @@ export default class Temp extends Component {
} }
} }
class TempInputPair extends Component {
render() {
return (
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<TempInput
type='integer'
integer={this.props.integer}
fractional={this.props.fractional}
setState={this.props.setState}
isSuggestion={this.props.isSuggestion}
/>
<Text style={styles.temperatureTextInput}>.</Text>
<TempInput
type='fractional'
integer={this.props.integer}
fractional={this.props.fractional}
setState={this.props.setState}
isSuggestion={this.props.isSuggestion}
/>
</View>
)
}
}
class TempInput extends Component { class TempInput extends Component {
checkRange = () => { checkRange = () => {
const value = Number(`${this.props.integer}.${this.props.fractional}`) const value = Number(this.props.value)
console.log(value)
if (isNaN(value)) return if (isNaN(value)) return
const scale = scaleObservable.value const scale = scaleObservable.value
if (value < scale.min || value > scale.max) { if (value < scale.min || value > scale.max) {
...@@ -164,13 +137,12 @@ class TempInput extends Component { ...@@ -164,13 +137,12 @@ class TempInput extends Component {
style={style} style={style}
onChangeText={(val) => { onChangeText={(val) => {
if (isNaN(Number(val))) return if (isNaN(Number(val))) return
this.props.setState({ [this.props.type]: val, isSuggestion: false }) this.props.setState({ temperature: val, isSuggestion: false })
}} }}
keyboardType='numeric' keyboardType='numeric'
value={this.props[this.props.type]} value={this.props.value}
onBlur={this.checkRange} onBlur={this.checkRange}
maxLength={2} autoFocus={true}
autoFocus={this.props.type === 'fractional'}
/> />
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment