diff --git a/components/cycle-day/cycle-day-overview.js b/components/cycle-day/cycle-day-overview.js index baccc503db2dda8583d7430950fbc825f5446646..0c9b9d7b2921197516297bea48938f9458bb8ca9 100644 --- a/components/cycle-day/cycle-day-overview.js +++ b/components/cycle-day/cycle-day-overview.js @@ -20,7 +20,9 @@ import { cervixOpening as openingLabels, cervixFirmness as firmnessLabels, cervixPosition as positionLabels, - intensity as intensityLabels + intensity as intensityLabels, + pain as painLabels, + sex as sexLabels } from './labels/labels' export default class CycleDayOverView extends Component { @@ -101,6 +103,11 @@ export default class CycleDayOverView extends Component { onPress={() => this.navigate('NoteEditView')} data={getLabel('note', cycleDay.note)} /> + <SymptomBox + title='Pain' + onPress={() => this.navigate('PainEditView')} + data={getLabel('pain', cycleDay.pain)} + /> {/* this is just to make the last row adhere to the grid (and) because there are no pseudo properties in RN */} <FillerBoxes /> @@ -163,15 +170,42 @@ function getLabel(symptomName, symptom) { } }, sex: sex => { - const sexLabel = [] - if ( sex.solo || sex.partner ) { - sexLabel.push('activity') + let sexLabel = [] + if (sex && Object.values(sex).some(val => val)){ + Object.keys(sex).forEach(key => { + if(sex[key] && key !== 'other' && key !== 'note') { + sexLabel.push(sexLabels[key]) + } + if(key === 'other' && sex.other) { + let label = sexLabels[key] + if(sex.note) { + label = `${label} (${sex.note})` + } + sexLabel.push(label) + } + }) + sexLabel = sexLabel.join(', ') } - if (sex.condom || sex.pill || sex.iud || - sex.patch || sex.ring || sex.implant || sex.other) { - sexLabel.push('contraceptive') + return sexLabel + }, + pain: pain => { + let painLabel = [] + if (pain && Object.values(pain).some(val => val)){ + Object.keys(pain).forEach(key => { + if(pain[key] && key !== 'other' && key !== 'note') { + painLabel.push(painLabels[key]) + } + if(key === 'other' && pain.other) { + let label = painLabels[key] + if(pain.note) { + label = `${label} (${pain.note})` + } + painLabel.push(label) + } + }) + painLabel = painLabel.join(', ') } - return sexLabel.join(', ') + return painLabel } } @@ -223,4 +257,4 @@ class FillerBoxes extends Component { } return fillerBoxes } -} \ No newline at end of file +} diff --git a/components/cycle-day/labels/labels.js b/components/cycle-day/labels/labels.js index 6650e335efde0c62ad1e55ba181dd230e0db7e2f..90faf28acf603e0bea205e253323be41c48bc0f0 100644 --- a/components/cycle-day/labels/labels.js +++ b/components/cycle-day/labels/labels.js @@ -6,11 +6,9 @@ export const cervixOpening = ['closed', 'medium', 'open'] export const cervixFirmness = ['hard', 'soft'] export const cervixPosition = ['low', 'medium', 'high'] export const intensity = ['low', 'medium', 'high'] -export const sexActivity = { +export const sex = { solo: 'Solo', - partner: 'Partner' -} -export const contraceptives = { + partner: 'Partner', condom: 'Condom', pill: 'Pill', iud: 'IUD', @@ -20,6 +18,18 @@ export const contraceptives = { other: 'Other' } +export const pain = { + cramps: 'Cramps', + ovulationPain: 'Ovulation pain', + headache: 'Headache', + backache: 'Backache', + nausea: 'Nausea', + tenderBreasts: 'Tender breasts', + migraine: 'Migraine', + other: 'Other', + note: 'Note' +} + export const fertilityStatus = { fertile: 'fertile', infertile: 'infertile', diff --git a/components/cycle-day/symptoms/index.js b/components/cycle-day/symptoms/index.js index 12622b73c88b75d29edba5def57ee217b355d28e..014e9fe5dc4fa8aff3e83cf9ca275be1dfbd73ed 100644 --- a/components/cycle-day/symptoms/index.js +++ b/components/cycle-day/symptoms/index.js @@ -5,6 +5,7 @@ import CervixEditView from './cervix' import NoteEditView from './note' import DesireEditView from './desire' import SexEditView from './sex' +import PainEditView from './pain' export default { BleedingEditView, @@ -13,5 +14,6 @@ export default { CervixEditView, NoteEditView, DesireEditView, - SexEditView -} \ No newline at end of file + SexEditView, + PainEditView +} diff --git a/components/cycle-day/symptoms/note.js b/components/cycle-day/symptoms/note.js index 6bf0cb63dc0a32677281de1d1508f09968700ee2..3e36441f6bc495e8ebf660e8416438d81ebc45c9 100644 --- a/components/cycle-day/symptoms/note.js +++ b/components/cycle-day/symptoms/note.js @@ -9,7 +9,7 @@ import styles from '../../../styles' import { saveSymptom } from '../../../db' import ActionButtonFooter from './action-button-footer' -export default class Temp extends Component { +export default class Note extends Component { constructor(props) { super(props) this.cycleDay = props.cycleDay @@ -27,6 +27,7 @@ export default class Temp extends Component { <ScrollView> <View style={styles.symptomViewRow}> <TextInput + autoFocus={!this.state.currentValue} multiline={true} placeholder="Enter" onChangeText={(val) => { @@ -50,4 +51,4 @@ export default class Temp extends Component { </View> ) } -} \ No newline at end of file +} diff --git a/components/cycle-day/symptoms/pain.js b/components/cycle-day/symptoms/pain.js new file mode 100644 index 0000000000000000000000000000000000000000..6365065329cc36c18a41f970fdc34ddeb664d620 --- /dev/null +++ b/components/cycle-day/symptoms/pain.js @@ -0,0 +1,144 @@ +import React, { Component } from 'react' +import { + CheckBox, + ScrollView, + Text, + TextInput, + View +} from 'react-native' +import styles from '../../../styles' +import { saveSymptom } from '../../../db' +import { + pain as painLabels +} from '../labels/labels' +import ActionButtonFooter from './action-button-footer' + +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 + } + } + } + + render() { + return ( + <View style={{ flex: 1 }}> + <ScrollView> + <View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}>{painLabels.cramps}</Text> + <CheckBox + value={this.state.cramps} + onValueChange={(val) => { + this.setState({cramps: val}) + }} + /> + <Text style={styles.symptomDayView}> + {painLabels.ovulationPain} + </Text> + <CheckBox + value={this.state.ovulationPain} + onValueChange={(val) => { + this.setState({ovulationPain: val}) + }} + /> + </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {painLabels.headache} + </Text> + <CheckBox + value={this.state.headache} + onValueChange={(val) => { + this.setState({headache: val}) + }} + /> + <Text style={styles.symptomDayView}> + {painLabels.backache} + </Text> + <CheckBox + value={this.state.backache} + onValueChange={(val) => { + this.setState({backache: val}) + }} + /> + </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {painLabels.nausea} + </Text> + <CheckBox + value={this.state.nausea} + onValueChange={(val) => { + this.setState({nausea: val}) + }} + /> + <Text style={styles.symptomDayView}> + {painLabels.tenderBreasts} + </Text> + <CheckBox + value={this.state.tenderBreasts} + onValueChange={(val) => { + this.setState({tenderBreasts: val}) + }} + /> + </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {painLabels.migraine} + </Text> + <CheckBox + value={this.state.migraine} + onValueChange={(val) => { + this.setState({migraine: val}) + }} + /> + <Text style={styles.symptomDayView}> + {painLabels.other} + </Text> + <CheckBox + value={this.state.other} + onValueChange={(val) => { + this.setState({ + other: val, + focusTextArea: true + }) + }} + /> + </View> + { this.state.other && + <TextInput + autoFocus={this.state.focusTextArea} + multiline={true} + placeholder="Enter" + value={this.state.note} + onChangeText={(val) => { + this.setState({note: val}) + }} + /> + } + </View> + </ScrollView> + <ActionButtonFooter + symptom='pain' + cycleDay={this.cycleDay} + saveAction={() => { + const copyOfState = Object.assign({}, this.state) + if (!copyOfState.other) { + copyOfState.note = null + } + saveSymptom('pain', this.cycleDay, copyOfState) + }} + saveDisabled={Object.values(this.state).every(value => !value)} + navigate={this.props.navigate} + /> + </View> + ) + } +} diff --git a/components/cycle-day/symptoms/sex.js b/components/cycle-day/symptoms/sex.js index 2ca06eff057b941bd264e9c5fc83193414601883..f90db2193d110418e80bfc33b377d0c911ca17f6 100644 --- a/components/cycle-day/symptoms/sex.js +++ b/components/cycle-day/symptoms/sex.js @@ -8,10 +8,7 @@ import { } from 'react-native' import styles from '../../../styles' import { saveSymptom } from '../../../db' -import { - sexActivity as activityLabels, - contraceptives as contraceptiveLabels -} from '../labels/labels' +import { sex as sexLabels } from '../labels/labels' import ActionButtonFooter from './action-button-footer' export default class Sex extends Component { @@ -36,14 +33,16 @@ export default class Sex extends Component { <ScrollView> <View> <View style={styles.symptomViewRowInline}> - <Text style={styles.symptomDayView}>{activityLabels.solo}</Text> + <Text style={styles.symptomDayView}>{sexLabels.solo}</Text> <CheckBox value={this.state.solo} onValueChange={(val) => { this.setState({ solo: val }) }} /> - <Text style={styles.symptomDayView}>{activityLabels.partner}</Text> + <Text style={styles.symptomDayView}> + {sexLabels.partner} + </Text> <CheckBox value={this.state.partner} onValueChange={(val) => { @@ -54,7 +53,7 @@ export default class Sex extends Component { <Text style={styles.symptomDayView}>CONTRACEPTIVES</Text> <View style={styles.symptomViewRowInline}> <Text style={styles.symptomDayView}> - {contraceptiveLabels.condom} + {sexLabels.condom} </Text> <CheckBox value={this.state.condom} @@ -63,7 +62,7 @@ export default class Sex extends Component { }} /> <Text style={styles.symptomDayView}> - {contraceptiveLabels.pill} + {sexLabels.pill} </Text> <CheckBox value={this.state.pill} @@ -74,7 +73,7 @@ export default class Sex extends Component { </View> <View style={styles.symptomViewRowInline}> <Text style={styles.symptomDayView}> - {contraceptiveLabels.iud} + {sexLabels.iud} </Text> <CheckBox value={this.state.iud} @@ -83,7 +82,7 @@ export default class Sex extends Component { }} /> <Text style={styles.symptomDayView}> - {contraceptiveLabels.patch} + {sexLabels.patch} </Text> <CheckBox value={this.state.patch} @@ -94,7 +93,7 @@ export default class Sex extends Component { </View> <View style={styles.symptomViewRowInline}> <Text style={styles.symptomDayView}> - {contraceptiveLabels.ring} + {sexLabels.ring} </Text> <CheckBox value={this.state.ring} @@ -103,7 +102,7 @@ export default class Sex extends Component { }} /> <Text style={styles.symptomDayView}> - {contraceptiveLabels.implant} + {sexLabels.implant} </Text> <CheckBox value={this.state.implant} @@ -114,7 +113,7 @@ export default class Sex extends Component { </View> <View style={styles.symptomViewRowInline}> <Text style={styles.symptomDayView}> - {contraceptiveLabels.other} + {sexLabels.other} </Text> <CheckBox value={this.state.other} @@ -155,4 +154,4 @@ export default class Sex extends Component { </View> ) } -} \ No newline at end of file +} diff --git a/components/labels.js b/components/labels.js index 5f32eb54ff7739ee80ae6da8c1eb9a93ace326d7..c4c9cba75ad18957e1ba4dce0ffb609f9cfc389a 100644 --- a/components/labels.js +++ b/components/labels.js @@ -63,7 +63,8 @@ export const headerTitles = { CervixEditView: 'Cervix', NoteEditView: 'Note', DesireEditView: 'Desire', - SexEditView: 'Sex' + SexEditView: 'Sex', + PainEditView: 'Pain' } export const stats = { diff --git a/db/index.js b/db/index.js index be82049d86962e32a63de9806e029c6ceb6f42cb..184567418143141b300a57fb638d542df26d2e2a 100644 --- a/db/index.js +++ b/db/index.js @@ -80,6 +80,21 @@ const SexSchema = { } } +const PainSchema = { + name: 'Pain', + properties: { + cramps: { type: 'bool', optional: true }, + ovulationPain: { type: 'bool', optional: true }, + headache: { type: 'bool', optional: true }, + backache: { type: 'bool', optional: true }, + nausea: { type: 'bool', optional: true }, + tenderBreasts: { type: 'bool', optional: true }, + migraine: { type: 'bool', optional: true }, + other: { type: 'bool', optional: true }, + note: { type: 'string', optional: true } + } +} + const CycleDaySchema = { name: 'CycleDay', primaryKey: 'date', @@ -112,6 +127,10 @@ const CycleDaySchema = { sex: { type: 'Sex', optional: true + }, + pain: { + type: 'Pain', + optional: true } } } @@ -125,7 +144,8 @@ const realmConfig = { CervixSchema, NoteSchema, DesireSchema, - SexSchema + SexSchema, + PainSchema ], // we only want this in dev mode deleteRealmIfMigrationNeeded: true