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