When nothing entered, delete entry

This commit is contained in:
Julia Friesel
2019-05-12 12:47:05 +02:00
parent 08fd3afc34
commit ecf3ebf16d
10 changed files with 101 additions and 39 deletions
+8 -3
View File
@@ -5,7 +5,6 @@ import {
ScrollView ScrollView
} from 'react-native' } from 'react-native'
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import { bleeding } from '../../../i18n/en/cycle-day' import { bleeding } from '../../../i18n/en/cycle-day'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
import SelectTabGroup from '../select-tab-group' import SelectTabGroup from '../select-tab-group'
@@ -23,8 +22,14 @@ export default class Bleeding extends SymptomView {
} }
} }
save() { symptomName = 'bleeding'
saveSymptom('bleeding', this.props.date, {
onBackButtonPress() {
if (typeof this.state.currentValue != 'number') {
this.deleteSymptomEntry()
return
}
this.saveSymptomEntry({
value: this.state.currentValue, value: this.state.currentValue,
exclude: this.state.exclude exclude: this.state.exclude
}) })
+11 -11
View File
@@ -14,14 +14,22 @@ import SymptomView from './symptom-view'
export default class Cervix extends SymptomView { export default class Cervix extends SymptomView {
constructor(props) { constructor(props) {
super() super(props)
const cycleDay = props.cycleDay const cycleDay = props.cycleDay
this.cervix = cycleDay && cycleDay.cervix this.cervix = cycleDay && cycleDay.cervix
this.state = this.cervix ? this.cervix : {} this.state = this.cervix ? this.cervix : {}
} }
save() { symptomName = 'cervix'
saveSymptom('cervix', this.props.date, {
onBackButtonPress() {
const nothingEntered = ['opening', 'firmness', 'position'].every(val => typeof this.state[val] != 'number')
if (nothingEntered) {
this.deleteSymptomEntry()
return
}
this.saveSymptomEntry({
opening: this.state.opening, opening: this.state.opening,
firmness: this.state.firmness, firmness: this.state.firmness,
position: this.state.position, position: this.state.position,
@@ -95,14 +103,6 @@ export default class Cervix extends SymptomView {
symptom='cervix' symptom='cervix'
date={this.props.date} date={this.props.date}
currentSymptomValue={this.cervix} currentSymptomValue={this.cervix}
saveAction={() => {
saveSymptom('cervix', this.props.date, {
opening: this.state.opening,
firmness: this.state.firmness,
position: this.state.position,
exclude: Boolean(this.state.exclude)
})
}}
navigate={this.props.navigate} navigate={this.props.navigate}
/> />
</View> </View>
+9 -4
View File
@@ -4,7 +4,6 @@ import {
ScrollView ScrollView
} from 'react-native' } from 'react-native'
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import { intensity, desire } from '../../../i18n/en/cycle-day' import { intensity, desire } from '../../../i18n/en/cycle-day'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
import SelectTabGroup from '../select-tab-group' import SelectTabGroup from '../select-tab-group'
@@ -13,15 +12,21 @@ import SymptomView from './symptom-view'
export default class Desire extends SymptomView { export default class Desire extends SymptomView {
constructor(props) { constructor(props) {
super() super(props)
const cycleDay = props.cycleDay const cycleDay = props.cycleDay
this.desire = cycleDay && cycleDay.desire this.desire = cycleDay && cycleDay.desire
const desireValue = this.desire && this.desire.value const desireValue = this.desire && this.desire.value
this.state = { currentValue: desireValue } this.state = { currentValue: desireValue }
} }
save() { symptomName = 'desire'
saveSymptom('desire', this.props.date, { value: this.state.currentValue })
onBackButtonPress() {
if (!this.state.currentValue) {
this.deleteSymptomEntry()
return
}
this.saveSymptomEntry({ value: this.state.currentValue })
} }
render() { render() {
+10 -4
View File
@@ -4,7 +4,6 @@ import {
TextInput, TextInput,
View View
} from 'react-native' } from 'react-native'
import { saveSymptom } from '../../../db'
import { mood as labels } from '../../../i18n/en/cycle-day' import { mood as labels } from '../../../i18n/en/cycle-day'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
import SelectBoxGroup from '../select-box-group' import SelectBoxGroup from '../select-box-group'
@@ -14,7 +13,7 @@ import SymptomView from './symptom-view'
export default class Mood extends SymptomView { export default class Mood extends SymptomView {
constructor(props) { constructor(props) {
super() super(props)
const cycleDay = props.cycleDay const cycleDay = props.cycleDay
if (cycleDay && cycleDay.mood) { if (cycleDay && cycleDay.mood) {
this.state = Object.assign({}, cycleDay.mood) this.state = Object.assign({}, cycleDay.mood)
@@ -26,12 +25,19 @@ export default class Mood extends SymptomView {
} }
} }
save() { symptomName = "mood"
onBackButtonPress() {
const nothingEntered = Object.values(this.state).every(val => !val)
if (nothingEntered) {
this.deleteSymptomEntry()
return
}
const copyOfState = Object.assign({}, this.state) const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) { if (!copyOfState.other) {
copyOfState.note = null copyOfState.note = null
} }
saveSymptom('mood', this.props.date, copyOfState) this.saveSymptomEntry(copyOfState)
} }
toggleState = (key) => { toggleState = (key) => {
+11 -4
View File
@@ -5,7 +5,6 @@ import {
ScrollView ScrollView
} from 'react-native' } from 'react-native'
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import { mucus as labels } from '../../../i18n/en/cycle-day' import { mucus as labels } from '../../../i18n/en/cycle-day'
import computeNfpValue from '../../../lib/nfp-mucus' import computeNfpValue from '../../../lib/nfp-mucus'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
@@ -15,16 +14,24 @@ import SymptomView from './symptom-view'
export default class Mucus extends SymptomView { export default class Mucus extends SymptomView {
constructor(props) { constructor(props) {
super() super(props)
const cycleDay = props.cycleDay const cycleDay = props.cycleDay
this.mucus = cycleDay && cycleDay.mucus this.mucus = cycleDay && cycleDay.mucus
this.state = this.mucus ? this.mucus : {} this.state = this.mucus ? this.mucus : {}
} }
save() { symptomName = 'mucus'
onBackButtonPress() {
const nothingEntered = ['feeling', 'texture'].every(val => typeof this.state[val] != 'number')
if (nothingEntered) {
this.deleteSymptomEntry()
return
}
const feeling = this.state.feeling const feeling = this.state.feeling
const texture = this.state.texture const texture = this.state.texture
saveSymptom('mucus', this.props.date, { this.saveSymptomEntry({
feeling, feeling,
texture, texture,
value: computeNfpValue(feeling, texture), value: computeNfpValue(feeling, texture),
+8 -2
View File
@@ -24,8 +24,14 @@ export default class Note extends SymptomView {
} }
} }
save() { symptomName = 'note'
saveSymptom('note', this.props.date, {
onBackButtonPress() {
if (!this.state.currentValue) {
this.deleteSymptomEntry()
return
}
this.saveSymptomEntry({
value: this.state.currentValue value: this.state.currentValue
}) })
} }
+10 -2
View File
@@ -27,12 +27,20 @@ export default class Pain extends SymptomView {
} }
} }
save() { symptomName = 'pain'
onBackButtonPress() {
const nothingEntered = Object.values(this.state).every(val => !val)
if (nothingEntered) {
this.deleteSymptomEntry()
return
}
const copyOfState = Object.assign({}, this.state) const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) { if (!copyOfState.other) {
copyOfState.note = null copyOfState.note = null
} }
saveSymptom('pain', this.props.date, copyOfState) this.saveSymptomEntry(copyOfState)
} }
toggleState = (key) => { toggleState = (key) => {
+10 -3
View File
@@ -5,7 +5,6 @@ import {
ScrollView ScrollView
} from 'react-native' } from 'react-native'
import styles from '../../../styles' import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import { sex as sexLabels, contraceptives as contraceptivesLabels } from '../../../i18n/en/cycle-day' import { sex as sexLabels, contraceptives as contraceptivesLabels } from '../../../i18n/en/cycle-day'
import { shared as sharedLabels } from '../../../i18n/en/labels' import { shared as sharedLabels } from '../../../i18n/en/labels'
import ActionButtonFooter from './action-button-footer' import ActionButtonFooter from './action-button-footer'
@@ -27,12 +26,20 @@ export default class Sex extends SymptomView {
if (this.state.note) this.state.other = true if (this.state.note) this.state.other = true
} }
save() { symptomName = "sex"
onBackButtonPress() {
const nothingEntered = Object.values(this.state).every(val => !val)
if (nothingEntered) {
this.deleteSymptomEntry()
return
}
const copyOfState = Object.assign({}, this.state) const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) { if (!copyOfState.other) {
copyOfState.note = null copyOfState.note = null
} }
saveSymptom('sex', this.props.date, copyOfState) this.saveSymptomEntry(copyOfState)
} }
toggleState = (key) => { toggleState = (key) => {
+13 -2
View File
@@ -1,10 +1,21 @@
import { Component } from 'react' import { Component } from 'react'
import { BackHandler } from 'react-native' import { BackHandler } from 'react-native'
import { saveSymptom } from '../../../db'
export default class SymptomView extends Component { export default class SymptomView extends Component {
constructor() { constructor(props) {
super() super()
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.save.bind(this)) this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.onBackButtonPress.bind(this))
this.symptomName = props.symptomName
this.date = props.date
}
saveSymptomEntry(entry) {
saveSymptom(this.symptomName, this.date, entry)
}
deleteSymptomEntry() {
saveSymptom(this.symptomName, this.date)
} }
componentWillUnmount() { componentWillUnmount() {
+11 -4
View File
@@ -9,7 +9,7 @@ import {
import DateTimePicker from 'react-native-modal-datetime-picker-nevo' import DateTimePicker from 'react-native-modal-datetime-picker-nevo'
import padWithZeros from '../../helpers/pad-time-with-zeros' import padWithZeros from '../../helpers/pad-time-with-zeros'
import { getPreviousTemperature, saveSymptom } from '../../../db' import { getPreviousTemperature } from '../../../db'
import styles from '../../../styles' import styles from '../../../styles'
import { LocalTime, ChronoUnit } from 'js-joda' import { LocalTime, ChronoUnit } from 'js-joda'
import { temperature as labels } from '../../../i18n/en/cycle-day' import { temperature as labels } from '../../../i18n/en/cycle-day'
@@ -54,7 +54,14 @@ export default class Temp extends SymptomView {
} }
} }
save() { symptomName = 'temperature'
onBackButtonPress() {
if (this.state.temperature === '') {
this.deleteSymptomEntry()
return
}
this.checkRangeAndSave() this.checkRangeAndSave()
} }
@@ -65,8 +72,8 @@ export default class Temp extends SymptomView {
time: this.state.time, time: this.state.time,
note: this.state.note note: this.state.note
} }
saveSymptom('temperature', this.props.date, dataToSave)
this.props.navigate('CycleDay', {date: this.props.date}) this.saveSymptomEntry(dataToSave)
} }
checkRangeAndSave = () => { checkRangeAndSave = () => {