From 0f7ab6c8038bf3486889b873dbd480c2aff44018 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Fri, 17 May 2019 16:09:49 +0200 Subject: [PATCH] Let symptom views overwrite isDeleteIconActive method --- components/cycle-day/symptoms/symptom-view.js | 12 ++++++++---- components/cycle-day/symptoms/temperature.js | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/cycle-day/symptoms/symptom-view.js b/components/cycle-day/symptoms/symptom-view.js index 9c58599..b782a12 100644 --- a/components/cycle-day/symptoms/symptom-view.js +++ b/components/cycle-day/symptoms/symptom-view.js @@ -34,6 +34,13 @@ export default class SymptomView extends Component { this.backHandler.remove() } + isDeleteIconActive() { + return Object.values(this.state).some(value => { + // is there any meaningful value in the current state? + return value || value === 0 + }) + } + render() { return ( @@ -41,10 +48,7 @@ export default class SymptomView extends Component { title={headerTitles[this.symptomName].toLowerCase()} date={this.date} goBack={this.handleBackButtonPressOnSymptomView.bind(this)} - deleteIconActive={Object.values(this.state).some(x => { - // is there any meaningful value in the current state? - return x || x === 0 - })} + deleteIconActive={this.isDeleteIconActive()} deleteEntry={() => { Alert.alert( sharedDialogs.areYouSureTitle, diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index 3bb08c9..810713e 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -55,6 +55,15 @@ export default class Temp extends SymptomView { symptomName = 'temperature' + isDeleteIconActive() { + return Object.keys(this.state).some(key => { + // the time is always prefilled, so it's not relevant for setting + // the delete button active + if (key === 'time') return + return this.state[key] || this.state[key] === 0 + }) + } + async onBackButtonPress() { if (typeof this.state.temperature != 'string' || this.state.temperature === '') { this.deleteSymptomEntry()