From 12b8e5c21323fb20dc6e32809ea900d3e4026e4b Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Sun, 1 Mar 2020 11:53:43 +0100 Subject: [PATCH 1/4] Removes unnecessary prop and defines the missing propTypes --- components/app.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/app.js b/components/app.js index ee84c5b..4953678 100644 --- a/components/app.js +++ b/components/app.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import { connect } from 'react-redux' -import { getDate, setDate } from '../slices/date' +import { getDate } from '../slices/date' import { getNavigation, navigate, goBack } from '../slices/navigation' import Header from './header' @@ -21,6 +21,8 @@ class App extends Component { static propTypes = { date: PropTypes.string, navigation: PropTypes.object.isRequired, + navigate: PropTypes.func, + goBack: PropTypes.func, } constructor(props) { @@ -89,7 +91,6 @@ const mapStateToProps = (state) => { const mapDispatchToProps = (dispatch) => { return({ - setDate: (date) => dispatch(setDate(date)), navigate: (page) => dispatch(navigate(page)), goBack: () => dispatch(goBack()), }) From 346d7e6dad3b5a23cc4e400f84a3473d3214e2d0 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Sun, 1 Mar 2020 14:15:52 +0100 Subject: [PATCH 2/4] 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 (
Date: Sun, 1 Mar 2020 14:29:29 +0100 Subject: [PATCH 3/4] Gets rid of a top level prop passed down through a tree of components --- components/app.js | 1 - components/cycle-day/symptoms/bleeding.js | 2 -- components/cycle-day/symptoms/cervix.js | 2 -- components/cycle-day/symptoms/desire.js | 2 -- components/cycle-day/symptoms/mood.js | 2 -- components/cycle-day/symptoms/mucus.js | 2 -- components/cycle-day/symptoms/note.js | 1 - components/cycle-day/symptoms/pain.js | 2 -- components/cycle-day/symptoms/sex.js | 2 -- components/cycle-day/symptoms/symptom-view.js | 19 +++++++++++++------ components/cycle-day/symptoms/temperature.js | 2 -- components/home.js | 3 +-- 12 files changed, 14 insertions(+), 26 deletions(-) diff --git a/components/app.js b/components/app.js index 4953678..6ae3e86 100644 --- a/components/app.js +++ b/components/app.js @@ -63,7 +63,6 @@ class App extends Component { const pageProps = { cycleDay: date && getCycleDay(date), date, - handleBackButtonPress: goBack, } return ( diff --git a/components/cycle-day/symptoms/bleeding.js b/components/cycle-day/symptoms/bleeding.js index a8ae709..f0579c1 100644 --- a/components/cycle-day/symptoms/bleeding.js +++ b/components/cycle-day/symptoms/bleeding.js @@ -14,7 +14,6 @@ class Bleeding extends Component { static propTypes = { cycleDay: PropTypes.object, - handleBackButtonPress: PropTypes.func, date: PropTypes.string.isRequired, } @@ -54,7 +53,6 @@ class Bleeding extends Component { { this.deleteSymptomEntry() - this.props.handleBackButtonPress() + this.props.goBack() } showConfirmationAlert = () => { @@ -75,13 +76,13 @@ class SymptomView extends Component { } render() { - const { symptom, date } = this.props + const { symptom, date, goBack } = this.props return (
{ return({ - date: getDate(state) + date: getDate(state), + }) +} + +const mapDispatchToProps = (dispatch) => { + return({ + goBack: () => dispatch(goBack()), }) } export default connect( mapStateToProps, - null + mapDispatchToProps, )(SymptomView) diff --git a/components/cycle-day/symptoms/temperature.js b/components/cycle-day/symptoms/temperature.js index f735001..5c033c9 100644 --- a/components/cycle-day/symptoms/temperature.js +++ b/components/cycle-day/symptoms/temperature.js @@ -20,7 +20,6 @@ class Temperature extends Component { static propTypes = { cycleDay: PropTypes.object, - handleBackButtonPress: PropTypes.func, date: PropTypes.string.isRequired, } @@ -90,7 +89,6 @@ class Temperature extends Component { cycleDay: PropTypes.object, date: PropTypes.string, - handleBackButtonPress: PropTypes.func, } constructor(props) { From 407bc2e524194ab91b070c292bcf2610d41281b5 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Tue, 3 Mar 2020 21:39:02 +0100 Subject: [PATCH 4/4] Adds propTypes definition --- components/cycle-day/cycle-day-overview.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/cycle-day/cycle-day-overview.js b/components/cycle-day/cycle-day-overview.js index 7415ab2..e653aa9 100644 --- a/components/cycle-day/cycle-day-overview.js +++ b/components/cycle-day/cycle-day-overview.js @@ -1,5 +1,6 @@ import React, { Component } from 'react' import { ScrollView, View } from 'react-native' +import PropTypes from 'prop-types' import { connect } from 'react-redux' import { getDate, setDate } from '../../slices/date' @@ -16,6 +17,16 @@ import { getCycleDay } from '../../db' import styles from '../../styles' class CycleDayOverView extends Component { + + static propTypes = { + navigate: PropTypes.func, + setDate: PropTypes.func, + // The following are not being used, + // we could see if it's possible to not pass them from the + cycleDay: PropTypes.object, + date: PropTypes.string, + } + constructor(props) { super(props) this.state = {