Auto save whenever symptom view updates

This commit is contained in:
Julia Friesel
2019-05-26 07:39:15 +02:00
parent f8eef66810
commit bc358bd9ed
9 changed files with 15 additions and 18 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ export default class Bleeding extends SymptomView {
symptomName = 'bleeding'
onBackButtonPress() {
autoSave = () => {
if (typeof this.state.currentValue != 'number') {
this.deleteSymptomEntry()
return
+1 -1
View File
@@ -19,7 +19,7 @@ export default class Cervix extends SymptomView {
symptomName = 'cervix'
onBackButtonPress() {
autoSave = () => {
const nothingEntered = ['opening', 'firmness', 'position'].every(val => typeof this.state[val] != 'number')
if (nothingEntered) {
this.deleteSymptomEntry()
+1 -1
View File
@@ -19,7 +19,7 @@ export default class Desire extends SymptomView {
symptomName = 'desire'
onBackButtonPress() {
autoSave = () => {
if (typeof this.state.currentValue != 'number') {
this.deleteSymptomEntry()
return
+1 -1
View File
@@ -24,7 +24,7 @@ export default class Mood extends SymptomView {
symptomName = "mood"
onBackButtonPress() {
autoSave = () => {
const nothingEntered = Object.values(this.state).every(val => !val)
if (nothingEntered) {
this.deleteSymptomEntry()
+1 -1
View File
@@ -20,7 +20,7 @@ export default class Mucus extends SymptomView {
symptomName = 'mucus'
onBackButtonPress() {
autoSave = () => {
const nothingEntered = ['feeling', 'texture'].every(val => typeof this.state[val] != 'number')
if (nothingEntered) {
this.deleteSymptomEntry()
+1 -1
View File
@@ -23,7 +23,7 @@ export default class Note extends SymptomView {
symptomName = 'note'
onBackButtonPress() {
autoSave = () => {
if (!this.state.currentValue) {
this.deleteSymptomEntry()
return
+1 -1
View File
@@ -26,7 +26,7 @@ export default class Pain extends SymptomView {
symptomName = 'pain'
onBackButtonPress() {
autoSave = () => {
const nothingEntered = Object.values(this.state).every(val => !val)
if (nothingEntered) {
this.deleteSymptomEntry()
+1 -1
View File
@@ -26,7 +26,7 @@ export default class Sex extends SymptomView {
symptomName = "sex"
onBackButtonPress() {
autoSave = () => {
const nothingEntered = Object.values(this.state).every(val => !val)
if (nothingEntered) {
this.deleteSymptomEntry()
+7 -10
View File
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import {
BackHandler, View, Alert, TouchableOpacity
View, Alert, TouchableOpacity
} from 'react-native'
import { saveSymptom } from '../../../db'
import InfoPopUp from './info-symptom'
@@ -13,11 +13,6 @@ import styles, { iconStyles } from '../../../styles'
export default class SymptomView extends Component {
constructor(props) {
super()
this.backHandler = BackHandler.addEventListener(
'hardwareBackPress',
this.handleBackButtonPressOnSymptomView.bind(this)
)
this.globalBackhandler = props.handleBackButtonPress
this.date = props.date
this.navigate = props.navigate
this.state = {
@@ -25,6 +20,11 @@ export default class SymptomView extends Component {
}
}
componentDidUpdate() {
this.autoSave()
}
// TODO where is this needed now?
async handleBackButtonPressOnSymptomView() {
// every specific symptom view provides their own onBackButtonPress method
const stopHere = await this.onBackButtonPress()
@@ -39,10 +39,6 @@ export default class SymptomView extends Component {
saveSymptom(this.symptomName, this.date)
}
componentWillUnmount() {
this.backHandler.remove()
}
isDeleteIconActive() {
const symptomValueHasBeenFilledOut = key => {
// the state tracks whether the symptom info should be shown,
@@ -63,6 +59,7 @@ export default class SymptomView extends Component {
<Header
title={headerTitles[this.symptomName].toLowerCase()}
date={this.date}
// TODO what to put here instead?
goBack={this.handleBackButtonPressOnSymptomView.bind(this)}
deleteIconActive={this.isDeleteIconActive()}
deleteEntry={() => {