diff --git a/components/cycle-day/cycle-day-overview.js b/components/cycle-day/cycle-day-overview.js index f92934b54305277f47588f56b4087ad296573db2..b127b7471fe1742792f6f1e3bf9b8bd781799515 100644 --- a/components/cycle-day/cycle-day-overview.js +++ b/components/cycle-day/cycle-day-overview.js @@ -98,11 +98,20 @@ export default class DayView extends Component { <Text style={styles.symptomDayView}>Desire</Text> <View style={styles.symptomEditButton}> <Button - onPress={() => this.showView('desireEditView')} + onPress={() => this.showView('DesireEditView')} title={getLabel('desire', cycleDay.desire)}> </Button> </View> </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}>Sex</Text> + <View style={styles.symptomEditButton}> + <Button + onPress={() => this.showView('SexEditView')} + title={getLabel('sex', cycleDay.sex)}> + </Button> + </View> + </View> </View > ) } @@ -132,15 +141,22 @@ function getLabel(symptomName, symptom) { typeof mucus.texture === 'number' && typeof mucus.value === 'number' ) { - let mucusLabel = `${feelingLabels[mucus.feeling]} + ${textureLabels[mucus.texture]} ( ${computeSensiplanMucusLabels[mucus.value]} )` + let mucusLabel = + `${feelingLabels[mucus.feeling]} + + ${textureLabels[mucus.texture]} + ( ${computeSensiplanMucusLabels[mucus.value]} )` if (mucus.exclude) mucusLabel = "( " + mucusLabel + " )" return mucusLabel } }, cervix: cervix => { if (cervix.opening > -1 && cervix.firmness > -1) { - let cervixLabel = `${openingLabels[cervix.opening]} + ${firmnessLabels[cervix.firmness]}` - if (cervix.position > -1) cervixLabel += `+ ${positionLabels[cervix.position]}` + let cervixLabel = + `${openingLabels[cervix.opening]} + + ${firmnessLabels[cervix.firmness]}` + if (cervix.position > -1) { + cervixLabel += `+ ${positionLabels[cervix.position]}` + } if (cervix.exclude) cervixLabel = "( " + cervixLabel + " )" return cervixLabel } @@ -153,6 +169,17 @@ function getLabel(symptomName, symptom) { const desireLabel = `${intensityLabels[desire.value]}` return desireLabel } + }, + sex: sex => { + let sexLabel = '' + if ( sex.solo || sex.partner ) { + sexLabel += 'Activity ' + } + if (sex.condom || sex.pill || sex.iud || + sex.patch || sex.ring || sex.implant || sex.other) { + sexLabel += 'Contraceptive' + } + return sexLabel ? sexLabel : 'edit' } } diff --git a/components/cycle-day/labels/labels.js b/components/cycle-day/labels/labels.js index 68735ee1305ea3cdfc2001311c716d67835a172f..ee88428f9eae95670ebf853af6ebafc85b4d33c7 100644 --- a/components/cycle-day/labels/labels.js +++ b/components/cycle-day/labels/labels.js @@ -6,6 +6,19 @@ 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 = { + solo: 'Solo', + partner: 'Partner' +} +export const contraceptives = { + condom: 'Condom', + pill: 'Pill', + iud: 'IUD', + patch: 'Patch', + ring: 'Ring', + implant: 'Implant', + other: 'Other' +} export const fertilityStatus = { fertile: 'fertile', diff --git a/components/cycle-day/symptoms/index.js b/components/cycle-day/symptoms/index.js index 617dbab46d2d1d59b522ddc17712a98271c1ed25..c3583df86348327d9dd3bdaa1d83975926d3694b 100644 --- a/components/cycle-day/symptoms/index.js +++ b/components/cycle-day/symptoms/index.js @@ -4,6 +4,7 @@ import MucusEditView from './mucus' import CervixEditView from './cervix' import NoteEditView from './note' import DesireEditView from './desire' +import SexEditView from './sex' export default { BleedingEditView, @@ -11,5 +12,6 @@ export default { MucusEditView, CervixEditView, NoteEditView, - DesireEditView -} \ No newline at end of file + DesireEditView, + SexEditView +} diff --git a/components/cycle-day/symptoms/sex.js b/components/cycle-day/symptoms/sex.js new file mode 100644 index 0000000000000000000000000000000000000000..d9ec3366402edab57e054a993363cecca41d6ab0 --- /dev/null +++ b/components/cycle-day/symptoms/sex.js @@ -0,0 +1,156 @@ +import React, { Component } from 'react' +import { + CheckBox, + Text, + TextInput, + View +} from 'react-native' +import styles from '../../../styles' +import { saveSymptom } from '../../../db' +import { + sexActivity as activityLabels, + contraceptives as contraceptiveLabels +} from '../labels/labels' + +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 + } + } + } + + render() { + + return ( + <View style={styles.symptomEditView}> + <Text style={styles.symptomDayView}>SEX</Text> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}>{activityLabels.solo}</Text> + <CheckBox + value={this.state.solo} + onValueChange={(val) => { + this.setState({solo: val}) + }} + /> + <Text style={styles.symptomDayView}>{activityLabels.partner}</Text> + <CheckBox + value={this.state.partner} + onValueChange={(val) => { + this.setState({partner: val}) + }} + /> + </View> + <Text style={styles.symptomDayView}>CONTRACEPTIVES</Text> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.condom} + </Text> + <CheckBox + value={this.state.condom} + onValueChange={(val) => { + this.setState({condom: val}) + }} + /> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.pill} + </Text> + <CheckBox + value={this.state.pill} + onValueChange={(val) => { + this.setState({pill: val}) + }} + /> + </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.iud} + </Text> + <CheckBox + value={this.state.iud} + onValueChange={(val) => { + this.setState({iud: val}) + }} + /> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.patch} + </Text> + <CheckBox + value={this.state.patch} + onValueChange={(val) => { + this.setState({patch: val}) + }} + /> + </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.ring} + </Text> + <CheckBox + value={this.state.ring} + onValueChange={(val) => { + this.setState({ring: val}) + }} + /> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.implant} + </Text> + <CheckBox + value={this.state.implant} + onValueChange={(val) => { + this.setState({implant: val}) + }} + /> + </View> + <View style={styles.symptomViewRowInline}> + <Text style={styles.symptomDayView}> + {contraceptiveLabels.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 style={styles.actionButtonRow}> + {this.props.makeActionButtons( + { + 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) + } + )} + </View> + </View> + ) + } +} diff --git a/db/index.js b/db/index.js index d3d49e87931d5290c9a88c9d37fdde71e2a891d3..f9747957b2bb2e502b6b6af09e354c46c272e74e 100644 --- a/db/index.js +++ b/db/index.js @@ -60,6 +60,22 @@ const DesireSchema = { } } +const SexSchema = { + name: 'Sex', + properties: { + solo: { type: 'bool', optional: true }, + partner: { type: 'bool', optional: true }, + condom: { type: 'bool', optional: true }, + pill: { type: 'bool', optional: true }, + iud: { type: 'bool', optional: true }, + patch: { type: 'bool', optional: true }, + ring: { type: 'bool', optional: true }, + implant: { type: 'bool', optional: true }, + other: { type: 'bool', optional: true }, + note: { type: 'string', optional: true } + } +} + const CycleDaySchema = { name: 'CycleDay', primaryKey: 'date', @@ -88,6 +104,10 @@ const CycleDaySchema = { desire: { type: 'Desire', optional: true + }, + sex: { + type: 'Sex', + optional: true } } } @@ -100,7 +120,8 @@ const realmConfig = { MucusSchema, CervixSchema, NoteSchema, - DesireSchema + DesireSchema, + SexSchema ], // we only want this in dev mode deleteRealmIfMigrationNeeded: true