From 346d7e6dad3b5a23cc4e400f84a3473d3214e2d0 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Sun, 1 Mar 2020 14:15:52 +0100 Subject: [PATCH] Cleanups symptom view --- components/cycle-day/symptoms/symptom-view.js | 49 +++++-------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/components/cycle-day/symptoms/symptom-view.js b/components/cycle-day/symptoms/symptom-view.js index 6b0398e..a84d93d 100644 --- a/components/cycle-day/symptoms/symptom-view.js +++ b/components/cycle-day/symptoms/symptom-view.js @@ -16,27 +16,30 @@ import { sharedDialogs } from '../../../i18n/en/cycle-day' import styles from '../../../styles' +const checkIfHasValues = data => { + const isMeaningfulValue = value => value || value === 0 + return Object.values(data).some(isMeaningfulValue) +} + class SymptomView extends Component { static propTypes = { symptom: PropTypes.string.isRequired, values: PropTypes.object, date: PropTypes.string, + handleBackButtonPress: PropTypes.func, + children: PropTypes.node, } constructor(props) { super() - this.values = props.values this.state = { - shouldShowDelete: this.checkIfHasValuesToDelete() + shouldShowDelete: checkIfHasValues(props.values) } - this.date = props.date - this.navigate = props.navigate } componentDidUpdate() { - this.values = this.props.values - const shouldShowDelete = this.checkIfHasValuesToDelete() + const shouldShowDelete = checkIfHasValues(this.props.values) if (shouldShowDelete !== this.state.shouldShowDelete) { this.setState({ shouldShowDelete }) } @@ -47,17 +50,6 @@ class SymptomView extends Component { saveSymptom(symptom, date, null) } - checkIfHasValuesToDelete() { - const valueHasBeenFilledOut = key => { - // is there any meaningful value in the current state? - return this.values[key] || this.values[key] === 0 - } - - const valuesKeys = Object.keys(this.values) - - return valuesKeys.some(valueHasBeenFilledOut) - } - onDeleteConfirmation = () => { this.deleteSymptomEntry() this.props.handleBackButtonPress() @@ -82,32 +74,13 @@ class SymptomView extends Component { ) } - showConfirmationAlert = () => { - - const cancelButton = { - text: sharedDialogs.cancel, - style: 'cancel' - } - - const confirmationButton = { - text: sharedDialogs.reallyDeleteData, - onPress: this.onDeleteConfirmation - } - - return Alert.alert( - sharedDialogs.areYouSureTitle, - sharedDialogs.areYouSureToDelete, - [cancelButton, confirmationButton] - ) - } - render() { - const { symptom } = this.props + const { symptom, date } = this.props return (