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
@@ -11,13 +11,14 @@ export default class ActionButtonFooter extends Component {
render() {
const {
symptom,
cycleDay,
currentSymptomValue,
date,
saveAction,
saveDisabled,
navigate,
autoShowDayView = true}
= this.props
const navigateToOverView = () => navigate('CycleDay', {cycleDay})
const navigateToOverView = () => navigate('CycleDay', {date})
const buttons = [
{
title: labels.unset,
@@ -31,13 +32,13 @@ export default class ActionButtonFooter extends Component {
}, {
text: labels.reallyUnsetData,
onPress: () => {
saveSymptom(symptom, cycleDay)
saveSymptom(symptom, date)
navigateToOverView()
}
}]
)
},
disabledCondition: !cycleDay[symptom],
disabledCondition: !currentSymptomValue,
icon: 'delete-outline'
}, {
title: labels.save,
+7 -5
View File
@@ -14,11 +14,12 @@ import SymptomSection from './symptom-section'
export default class Bleeding extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.bleeding = cycleDay && cycleDay.bleeding
this.makeActionButtons = props.makeActionButtons
this.state = {
currentValue: this.cycleDay.bleeding && this.cycleDay.bleeding.value,
exclude: this.cycleDay.bleeding ? this.cycleDay.bleeding.exclude : false
currentValue: this.bleeding && this.bleeding.value,
exclude: this.bleeding ? this.bleeding.exclude : false
}
}
@@ -57,9 +58,10 @@ export default class Bleeding extends Component {
</ScrollView>
<ActionButtonFooter
symptom='bleeding'
cycleDay={this.props.cycleDay}
date={this.props.date}
currentSymptomValue={this.bleeding}
saveAction={() => {
saveSymptom('bleeding', this.props.cycleDay, {
saveSymptom('bleeding', this.props.date, {
value: this.state.currentValue,
exclude: this.state.exclude
})
+7 -10
View File
@@ -14,14 +14,10 @@ import SymptomSection from './symptom-section'
export default class Cervix extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.cervix = cycleDay && cycleDay.cervix
this.makeActionButtons = props.makeActionButtons
this.state = {
exclude: this.cycleDay.cervix ? this.cycleDay.cervix.exclude : false,
opening: this.cycleDay.cervix ? this.cycleDay.cervix.opening : null,
firmness: this.cycleDay.cervix ? this.cycleDay.cervix.firmness : null,
position: this.cycleDay.cervix ? this.cycleDay.cervix.position : null
}
this.state = this.cervix ? this.cervix : {}
}
render() {
@@ -87,13 +83,14 @@ export default class Cervix extends Component {
</ScrollView>
<ActionButtonFooter
symptom='cervix'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.cervix}
saveAction={() => {
saveSymptom('cervix', this.cycleDay, {
saveSymptom('cervix', this.props.date, {
opening: this.state.opening,
firmness: this.state.firmness,
position: this.state.position,
exclude: this.state.exclude
exclude: Boolean(this.state.exclude)
})
}}
saveDisabled={typeof this.state.opening != 'number' || typeof this.state.firmness != 'number'}
+6 -4
View File
@@ -13,9 +13,10 @@ import SymptomSection from './symptom-section'
export default class Desire extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.desire = cycleDay && cycleDay.desire
this.makeActionButtons = props.makeActionButtons
const desireValue = this.cycleDay.desire && this.cycleDay.desire.value
const desireValue = this.desire && this.desire.value
this.state = { currentValue: desireValue }
}
@@ -41,9 +42,10 @@ export default class Desire extends Component {
</ScrollView>
<ActionButtonFooter
symptom='desire'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.desire}
saveAction={() => {
saveSymptom('desire', this.cycleDay, { value: this.state.currentValue })
saveSymptom('desire', this.props.date, { value: this.state.currentValue })
}}
saveDisabled={typeof this.state.currentValue != 'number'}
navigate={this.props.navigate}
+7 -9
View File
@@ -16,13 +16,10 @@ import SymptomSection from './symptom-section'
export default class Mucus extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.mucus = cycleDay && cycleDay.mucus
this.makeActionButtons = props.makeActionButtons
this.state = {
exclude: this.cycleDay.mucus ? this.cycleDay.mucus.exclude : false,
feeling: this.cycleDay.mucus ? this.cycleDay.mucus.feeling : null,
texture: this.cycleDay.mucus ? this.cycleDay.mucus.texture : null
}
this.state = this.mucus ? this.mucus : {}
}
render() {
@@ -75,15 +72,16 @@ export default class Mucus extends Component {
</ScrollView>
<ActionButtonFooter
symptom='mucus'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.mucus}
saveAction={() => {
const feeling = this.state.feeling
const texture = this.state.texture
saveSymptom('mucus', this.cycleDay, {
saveSymptom('mucus', this.props.date, {
feeling,
texture,
value: computeSensiplanValue(feeling, texture),
exclude: this.state.exclude
exclude: Boolean(this.state.exclude)
})
}}
saveDisabled={typeof this.state.feeling != 'number' || typeof this.state.texture != 'number'}
+6 -5
View File
@@ -14,12 +14,12 @@ import { noteExplainer } from '../labels'
export default class Note extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const note = this.cycleDay.note
const cycleDay = props.cycleDay
this.note = cycleDay && cycleDay.note
this.makeActionButtons = props.makeActionButtons
this.state = {
currentValue: note && note.value || ''
currentValue: this.note && this.note.value || ''
}
}
@@ -43,9 +43,10 @@ export default class Note extends Component {
</ScrollView>
<ActionButtonFooter
symptom='note'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.note}
saveAction={() => {
saveSymptom('note', this.cycleDay, {
saveSymptom('note', this.props.date, {
value: this.state.currentValue
})
}}
+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}
+16 -53
View File
@@ -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}
+8 -6
View File
@@ -25,10 +25,11 @@ const minutes = ChronoUnit.MINUTES
export default class Temp extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.temperature = cycleDay && cycleDay.temperature
this.makeActionButtons = props.makeActionButtons
const temp = this.cycleDay.temperature
const temp = this.temperature
this.state = {
exclude: temp ? temp.exclude : false,
@@ -44,7 +45,7 @@ export default class Temp extends Component {
this.state.temperature = `${this.state.temperature}.0`
}
} else {
const prevTemp = getPreviousTemperature(this.cycleDay)
const prevTemp = getPreviousTemperature(this.props.date)
if (prevTemp) {
this.state.temperature = prevTemp.toString()
this.state.isSuggestion = true
@@ -59,8 +60,8 @@ export default class Temp extends Component {
time: this.state.time,
note: this.state.note
}
saveSymptom('temperature', this.cycleDay, dataToSave)
this.props.navigate('CycleDay', {cycleDay: this.cycleDay})
saveSymptom('temperature', this.props.date, dataToSave)
this.props.navigate('CycleDay', {date: this.props.date})
}
checkRangeAndSave = () => {
@@ -164,7 +165,8 @@ export default class Temp extends Component {
</ScrollView>
<ActionButtonFooter
symptom='temperature'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.temperature}
saveAction={() => this.checkRangeAndSave()}
saveDisabled={
this.state.temperature === '' ||