Replace getOrCreateCycleDay
This commit is contained in:
@@ -6,61 +6,23 @@ import {
|
||||
} from 'react-native'
|
||||
import styles from '../../../styles'
|
||||
import { saveSymptom } from '../../../db'
|
||||
import { sex as labels } from '../labels'
|
||||
import { sex as sexLabels, contraceptives as cLabels } from '../labels'
|
||||
import ActionButtonFooter from './action-button-footer'
|
||||
import SelectBoxGroup from '../select-box-group'
|
||||
import SymptomSection from './symptom-section'
|
||||
|
||||
const sexBoxes = [{
|
||||
label: labels.solo,
|
||||
stateKey: 'solo'
|
||||
}, {
|
||||
label: labels.partner,
|
||||
stateKey: 'partner'
|
||||
}]
|
||||
|
||||
const contraceptiveBoxes = [{
|
||||
label: labels.condom,
|
||||
stateKey: 'condom'
|
||||
}, {
|
||||
label: labels.pill,
|
||||
stateKey: 'pill'
|
||||
}, {
|
||||
label: labels.iud,
|
||||
stateKey: 'iud'
|
||||
}, {
|
||||
label: labels.patch,
|
||||
stateKey: 'patch'
|
||||
}, {
|
||||
label: labels.ring,
|
||||
stateKey: 'ring'
|
||||
}, {
|
||||
label: labels.implant,
|
||||
stateKey: 'implant'
|
||||
}, {
|
||||
label: labels.diaphragm,
|
||||
stateKey: 'diaphragm'
|
||||
}, {
|
||||
label: labels.none,
|
||||
stateKey: 'none'
|
||||
}, {
|
||||
label: labels.other,
|
||||
stateKey: 'other'
|
||||
}]
|
||||
|
||||
export default class Sex extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.cycleDay = props.cycleDay
|
||||
this.state = {}
|
||||
if (this.cycleDay.sex !== null) {
|
||||
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
|
||||
}
|
||||
const cycleDay = props.cycleDay
|
||||
if (cycleDay && cycleDay.sex) {
|
||||
this.state = Object.assign({}, cycleDay.sex)
|
||||
} else {
|
||||
this.state = {}
|
||||
}
|
||||
// We make sure other is always true when there is a note,
|
||||
// e.g. when import is messed up.
|
||||
if (this.state.note) this.state.other = true
|
||||
}
|
||||
|
||||
toggleState = (key) => {
|
||||
@@ -77,20 +39,20 @@ export default class Sex extends Component {
|
||||
<ScrollView style={styles.page}>
|
||||
<SymptomSection
|
||||
header="Activity"
|
||||
explainer={labels.activityExplainer}
|
||||
explainer={sexLabels.explainer}
|
||||
>
|
||||
<SelectBoxGroup
|
||||
data={sexBoxes}
|
||||
labels={sexLabels.categories}
|
||||
onSelect={this.toggleState}
|
||||
optionsState={this.state}
|
||||
/>
|
||||
</SymptomSection>
|
||||
<SymptomSection
|
||||
header="Contraceptives"
|
||||
explainer={labels.contraceptiveExplainer}
|
||||
explainer={cLabels.explainer}
|
||||
>
|
||||
<SelectBoxGroup
|
||||
data={contraceptiveBoxes}
|
||||
labels={cLabels.categories}
|
||||
onSelect={this.toggleState}
|
||||
optionsState={this.state}
|
||||
/>
|
||||
@@ -110,13 +72,14 @@ export default class Sex extends Component {
|
||||
</ScrollView>
|
||||
<ActionButtonFooter
|
||||
symptom='sex'
|
||||
cycleDay={this.cycleDay}
|
||||
date={this.props.date}
|
||||
currentSymptomValue={this.state}
|
||||
saveAction={() => {
|
||||
const copyOfState = Object.assign({}, this.state)
|
||||
if (!copyOfState.other) {
|
||||
copyOfState.note = null
|
||||
}
|
||||
saveSymptom('sex', this.cycleDay, copyOfState)
|
||||
saveSymptom('sex', this.props.date, copyOfState)
|
||||
}}
|
||||
saveDisabled={Object.values(this.state).every(value => !value)}
|
||||
navigate={this.props.navigate}
|
||||
|
||||
Reference in New Issue
Block a user