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
+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={() => {