Merge branch 'master' into 73-implement-nfp-logic-for-mucus-mode
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import React, { Component } from 'react'
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
Switch
|
||||
} from 'react-native'
|
||||
import RadioForm from 'react-native-simple-radio-button'
|
||||
import styles from '../../../styles'
|
||||
import { saveSymptom } from '../../../db'
|
||||
import {
|
||||
cervixOpening as openingLabels,
|
||||
cervixFirmness as firmnessLabels,
|
||||
cervixPosition as positionLabels
|
||||
} from '../labels/labels'
|
||||
|
||||
export default class Cervix extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.cycleDay = props.cycleDay
|
||||
this.makeActionButtons = props.makeActionButtons
|
||||
this.state = {
|
||||
exclude: this.cycleDay.cervix ? this.cycleDay.cervix.exclude : false
|
||||
};
|
||||
|
||||
/* eslint-disable react/no-direct-mutation-state */
|
||||
['opening', 'firmness', 'position'].forEach(label => {
|
||||
this.state[label] = this.cycleDay.cervix && this.cycleDay.cervix[label]
|
||||
if (typeof this.state[label] !== 'number') {
|
||||
this.state[label] = -1
|
||||
}
|
||||
})
|
||||
/* eslint-enable react/no-direct-mutation-state */
|
||||
}
|
||||
|
||||
render() {
|
||||
const cervixOpeningRadioProps = [
|
||||
{label: openingLabels[0], value: 0},
|
||||
{label: openingLabels[1], value: 1},
|
||||
{label: openingLabels[2], value: 2}
|
||||
]
|
||||
const cervixFirmnessRadioProps = [
|
||||
{label: firmnessLabels[0], value: 0 },
|
||||
{label: firmnessLabels[1], value: 1 }
|
||||
]
|
||||
const cervixPositionRadioProps = [
|
||||
{label: positionLabels[0], value: 0 },
|
||||
{label: positionLabels[1], value: 1 },
|
||||
{label: positionLabels[2], value: 2 }
|
||||
]
|
||||
return(
|
||||
<View style={ styles.symptomEditView }>
|
||||
<Text style={styles.symptomDayView}>Cervix</Text>
|
||||
<Text style={styles.symptomDayView}>Opening</Text>
|
||||
<View style={styles.radioButtonRow}>
|
||||
<RadioForm
|
||||
radio_props={cervixOpeningRadioProps}
|
||||
initial={this.state.opening}
|
||||
formHorizontal={true}
|
||||
labelHorizontal={false}
|
||||
labelStyle={styles.radioButton}
|
||||
onPress={(itemValue) => {
|
||||
this.setState({opening: itemValue})
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
<Text style={styles.symptomDayView}>Firmness</Text>
|
||||
<View style={styles.radioButtonRow}>
|
||||
<RadioForm
|
||||
radio_props={cervixFirmnessRadioProps}
|
||||
initial={this.state.firmness}
|
||||
formHorizontal={true}
|
||||
labelHorizontal={false}
|
||||
labelStyle={styles.radioButton}
|
||||
onPress={(itemValue) => {
|
||||
this.setState({firmness: itemValue})
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
<Text style={styles.symptomDayView}>Position</Text>
|
||||
<View style={styles.radioButtonRow}>
|
||||
<RadioForm
|
||||
radio_props={cervixPositionRadioProps}
|
||||
initial={this.state.position}
|
||||
formHorizontal={true}
|
||||
labelHorizontal={false}
|
||||
labelStyle={styles.radioButton}
|
||||
onPress={(itemValue) => {
|
||||
this.setState({position: itemValue})
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.symptomViewRowInline}>
|
||||
<Text style={styles.symptomDayView}>Exclude</Text>
|
||||
<Switch
|
||||
onValueChange={(val) => {
|
||||
this.setState({ exclude: val })
|
||||
}}
|
||||
value={this.state.exclude}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.actionButtonRow}>
|
||||
{this.makeActionButtons(
|
||||
{
|
||||
symptom: 'cervix',
|
||||
cycleDay: this.cycleDay,
|
||||
saveAction: () => {
|
||||
saveSymptom('cervix', this.cycleDay, {
|
||||
opening: this.state.opening,
|
||||
firmness: this.state.firmness,
|
||||
position: this.state.position,
|
||||
exclude: this.state.exclude
|
||||
})
|
||||
},
|
||||
saveDisabled: this.state.opening === -1 || this.state.firmness === -1
|
||||
}
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,17 @@ export default class Mucus extends Component {
|
||||
this.makeActionButtons = props.makeActionButtons
|
||||
this.state = {
|
||||
exclude: this.cycleDay.mucus ? this.cycleDay.mucus.exclude : false
|
||||
}
|
||||
};
|
||||
|
||||
this.state.currentFeelingValue = this.cycleDay.mucus && this.cycleDay.mucus.feeling
|
||||
if (typeof this.state.currentFeelingValue !== 'number') {
|
||||
this.state.currentFeelingValue = -1
|
||||
}
|
||||
/* eslint-disable react/no-direct-mutation-state */
|
||||
['feeling', 'texture'].forEach(label => {
|
||||
this.state[label] = this.cycleDay.mucus && this.cycleDay.mucus[label]
|
||||
if (typeof this.state[label] !== 'number') {
|
||||
this.state[label] = -1
|
||||
}
|
||||
})
|
||||
/* eslint-enable react/no-direct-mutation-state */
|
||||
|
||||
this.state.currentTextureValue = this.cycleDay.mucus && this.cycleDay.mucus.texture
|
||||
if (typeof this.state.currentTextureValue !== 'number') {
|
||||
this.state.currentTextureValue = -1
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -53,12 +53,12 @@ export default class Mucus extends Component {
|
||||
<View style={styles.radioButtonRow}>
|
||||
<RadioForm
|
||||
radio_props={mucusFeelingRadioProps}
|
||||
initial={this.state.currentFeelingValue}
|
||||
initial={this.state.feeling}
|
||||
formHorizontal={true}
|
||||
labelHorizontal={false}
|
||||
labelStyle={styles.radioButton}
|
||||
onPress={(itemValue) => {
|
||||
this.setState({ currentFeelingValue: itemValue })
|
||||
this.setState({feeling: itemValue })
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
@@ -66,12 +66,12 @@ export default class Mucus extends Component {
|
||||
<View style={styles.radioButtonRow}>
|
||||
<RadioForm
|
||||
radio_props={mucusTextureRadioProps}
|
||||
initial={this.state.currentTextureValue}
|
||||
initial={this.state.texture}
|
||||
formHorizontal={true}
|
||||
labelHorizontal={false}
|
||||
labelStyle={styles.radioButton}
|
||||
onPress={(itemValue) => {
|
||||
this.setState({ currentTextureValue: itemValue })
|
||||
this.setState({texture: itemValue })
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
@@ -92,13 +92,13 @@ export default class Mucus extends Component {
|
||||
cycleDay: this.cycleDay,
|
||||
saveAction: () => {
|
||||
saveSymptom('mucus', this.cycleDay, {
|
||||
feeling: this.state.currentFeelingValue,
|
||||
texture: this.state.currentTextureValue,
|
||||
value: computeSensiplanValue(this.state.currentFeelingValue, this.state.currentTextureValue),
|
||||
feeling: this.state.feeling,
|
||||
texture: this.state.texture,
|
||||
value: computeSensiplanValue(this.state.feeling, this.state.texture),
|
||||
exclude: this.state.exclude
|
||||
})
|
||||
},
|
||||
saveDisabled: this.state.currentFeelingValue === -1 || this.state.currentTextureValue === -1
|
||||
saveDisabled: this.state.feeling === -1 || this.state.texture === -1
|
||||
}
|
||||
)}
|
||||
</View>
|
||||
|
||||
@@ -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'
|
||||
@@ -17,9 +19,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,7 +31,9 @@ export default class Temp extends Component {
|
||||
|
||||
this.state = {
|
||||
currentValue: initialValue,
|
||||
exclude: this.cycleDay.temperature ? this.cycleDay.temperature.exclude : false
|
||||
exclude: temp ? temp.exclude : false,
|
||||
time: this.time || LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString(),
|
||||
isTimePickerVisible: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +53,28 @@ export default class Temp extends Component {
|
||||
value={this.state.currentValue}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.symptomViewRowInline}>
|
||||
<Text style={styles.symptomDayView}>Time</Text>
|
||||
<TextInput
|
||||
style={styles.temperatureTextInput}
|
||||
onFocus={() => {
|
||||
Keyboard.dismiss()
|
||||
this.setState({isTimePickerVisible: true})
|
||||
}}
|
||||
value={this.state.time}
|
||||
/>
|
||||
</View>
|
||||
<DateTimePicker
|
||||
mode="time"
|
||||
isVisible={this.state.isTimePickerVisible}
|
||||
onConfirm={jsDate => {
|
||||
this.setState({
|
||||
time: `${jsDate.getHours()}:${jsDate.getMinutes()}`,
|
||||
isTimePickerVisible: false
|
||||
})
|
||||
}}
|
||||
onCancel={() => this.setState({isTimePickerVisible: false})}
|
||||
/>
|
||||
<View style={styles.symptomViewRowInline}>
|
||||
<Text style={styles.symptomDayView}>Exclude</Text>
|
||||
<Switch
|
||||
@@ -63,18 +91,24 @@ export default class Temp extends Component {
|
||||
saveAction: () => {
|
||||
const dataToSave = {
|
||||
value: Number(this.state.currentValue),
|
||||
exclude: this.state.exclude
|
||||
}
|
||||
if (!cycleDay.temperature || cycleDay.temperature && !cycleDay.temperature.time) {
|
||||
const now = LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString()
|
||||
dataToSave.time = now
|
||||
exclude: this.state.exclude,
|
||||
time: this.state.time
|
||||
}
|
||||
saveSymptom('temperature', cycleDay, dataToSave)
|
||||
},
|
||||
saveDisabled: this.state.currentValue === ''
|
||||
saveDisabled: this.state.currentValue === '' || isInvalidTime(this.state.time)
|
||||
})}
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function isInvalidTime(timeString) {
|
||||
try {
|
||||
LocalTime.parse(timeString)
|
||||
} catch (err) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user