Newer
Older
import React, { Component } from 'react'
import {
TextInput,
} from 'react-native'
import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import ActionButtonFooter from './action-button-footer'
import SelectBoxGroup from '../select-box-group'
import SymptomSection from './symptom-section'
const sexBoxes = [{
stateKey: 'solo'
}, {
stateKey: 'partner'
}]
const contraceptiveBoxes = [{
stateKey: 'condom'
}, {
stateKey: 'pill'
}, {
stateKey: 'iud'
}, {
stateKey: 'patch'
}, {
stateKey: 'ring'
}, {
stateKey: 'implant'
}, {
label: labels.diaphragm,
stateKey: 'diaphragm'
}, {
label: labels.none,
stateKey: 'none'
export default class Sex extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.state = {}
Object.assign(this.state, this.cycleDay.sex)
// We make sure other is always true when there is a note,
// e.g. when import is messed up.
if (this.cycleDay.sex && this.cycleDay.sex.note) {
this.state.other = true
}
}
}
toggleState = (key) => {
const curr = this.state[key]
this.setState({[key]: !curr})
if (key === 'other' && !curr) {
this.setState({focusTextArea: true})
}
}
render() {
<ScrollView style={styles.page}>
<SymptomSection
header="Activity"
explainer={labels.activityExplainer}
>
<SelectBoxGroup
data={sexBoxes}
onSelect={this.toggleState}
optionsState={this.state}
/>
</SymptomSection>
<SymptomSection
header="Contraceptives"
explainer={labels.contraceptiveExplainer}
>
<SelectBoxGroup
data={contraceptiveBoxes}
onSelect={this.toggleState}
optionsState={this.state}
/>
</SymptomSection>
{this.state.other &&
<TextInput
autoFocus={this.state.focusTextArea}
multiline={true}
placeholder="Enter"
value={this.state.note}
onChangeText={(val) => {
this.setState({ note: val })
}}
/>
}
<ActionButtonFooter
symptom='sex'
cycleDay={this.cycleDay}
saveAction={() => {
const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) {
copyOfState.note = null
saveSymptom('sex', this.cycleDay, copyOfState)
}}
saveDisabled={Object.values(this.state).every(value => !value)}
navigate={this.props.navigate}
/>