Auto save whenever symptom view updates
This commit is contained in:
@@ -22,7 +22,7 @@ export default class Bleeding extends SymptomView {
|
||||
|
||||
symptomName = 'bleeding'
|
||||
|
||||
onBackButtonPress() {
|
||||
autoSave = () => {
|
||||
if (typeof this.state.currentValue != 'number') {
|
||||
this.deleteSymptomEntry()
|
||||
return
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -19,7 +19,7 @@ export default class Desire extends SymptomView {
|
||||
|
||||
symptomName = 'desire'
|
||||
|
||||
onBackButtonPress() {
|
||||
autoSave = () => {
|
||||
if (typeof this.state.currentValue != 'number') {
|
||||
this.deleteSymptomEntry()
|
||||
return
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class Note extends SymptomView {
|
||||
|
||||
symptomName = 'note'
|
||||
|
||||
onBackButtonPress() {
|
||||
autoSave = () => {
|
||||
if (!this.state.currentValue) {
|
||||
this.deleteSymptomEntry()
|
||||
return
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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={() => {
|
||||
|
||||
Reference in New Issue
Block a user