Replace getOrCreateCycleDay

This commit is contained in:
Julia Friesel
2018-11-16 14:24:16 +01:00
parent ecca6cfda9
commit bb0a535d65
18 changed files with 255 additions and 309 deletions
+12 -37
View File
@@ -11,43 +11,17 @@ import SelectBoxGroup from '../select-box-group'
import SymptomSection from './symptom-section'
import styles from '../../../styles'
const categories = labels.categories
const boxes = [{
label: categories.cramps,
stateKey: 'cramps'
}, {
label: categories.ovulationPain,
stateKey: 'ovulationPain'
}, {
label: categories.headache,
stateKey: 'headache'
}, {
label: categories.backache,
stateKey: 'backache'
}, {
label: categories.nausea,
stateKey: 'nausea'
}, {
label: categories.tenderBreasts,
stateKey: 'tenderBreasts'
}, {
label: categories.migraine,
stateKey: 'migraine'
}, {
label: categories.other,
stateKey: 'other'
}]
export default class Pain extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.state = {}
if (this.cycleDay.pain !== null ) {
Object.assign(this.state, this.cycleDay.pain)
if (this.cycleDay.pain && this.cycleDay.pain.note) {
this.state.other = true
}
const cycleDay = props.cycleDay
if (cycleDay && cycleDay.pain) {
this.state = Object.assign({}, cycleDay.pain)
} else {
this.state = {}
}
if (this.state.note) {
this.state.other = true
}
}
@@ -67,7 +41,7 @@ export default class Pain extends Component {
explainer={labels.explainer}
>
<SelectBoxGroup
data={boxes}
labels={labels.categories}
onSelect={this.toggleState}
optionsState={this.state}
/>
@@ -86,13 +60,14 @@ export default class Pain extends Component {
</ScrollView>
<ActionButtonFooter
symptom='pain'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.state}
saveAction={() => {
const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) {
copyOfState.note = null
}
saveSymptom('pain', this.cycleDay, copyOfState)
saveSymptom('pain', this.props.date, copyOfState)
}}
saveDisabled={Object.values(this.state).every(value => !value)}
navigate={this.props.navigate}