Merge branch 'symptom-views-clean-up' into 'master'

Symptom views clean up

See merge request bloodyhealth/drip!267
This commit is contained in:
Maria Zadnepryanets
2020-03-04 20:52:41 +00:00
13 changed files with 37 additions and 64 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { getDate, setDate } from '../slices/date' import { getDate } from '../slices/date'
import { getNavigation, navigate, goBack } from '../slices/navigation' import { getNavigation, navigate, goBack } from '../slices/navigation'
import Header from './header' import Header from './header'
@@ -21,6 +21,8 @@ class App extends Component {
static propTypes = { static propTypes = {
date: PropTypes.string, date: PropTypes.string,
navigation: PropTypes.object.isRequired, navigation: PropTypes.object.isRequired,
navigate: PropTypes.func,
goBack: PropTypes.func,
} }
constructor(props) { constructor(props) {
@@ -61,7 +63,6 @@ class App extends Component {
const pageProps = { const pageProps = {
cycleDay: date && getCycleDay(date), cycleDay: date && getCycleDay(date),
date, date,
handleBackButtonPress: goBack,
} }
return ( return (
@@ -89,7 +90,6 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return({ return({
setDate: (date) => dispatch(setDate(date)),
navigate: (page) => dispatch(navigate(page)), navigate: (page) => dispatch(navigate(page)),
goBack: () => dispatch(goBack()), goBack: () => dispatch(goBack()),
}) })
@@ -1,5 +1,6 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { ScrollView, View } from 'react-native' import { ScrollView, View } from 'react-native'
import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { getDate, setDate } from '../../slices/date' import { getDate, setDate } from '../../slices/date'
@@ -16,6 +17,16 @@ import { getCycleDay } from '../../db'
import styles from '../../styles' import styles from '../../styles'
class CycleDayOverView extends Component { 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 <App />
cycleDay: PropTypes.object,
date: PropTypes.string,
}
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
@@ -14,7 +14,6 @@ class Bleeding extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -54,7 +53,6 @@ class Bleeding extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-2
View File
@@ -14,7 +14,6 @@ class Cervix extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -62,7 +61,6 @@ class Cervix extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-2
View File
@@ -13,7 +13,6 @@ class Desire extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -50,7 +49,6 @@ class Desire extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-2
View File
@@ -13,7 +13,6 @@ class Mood extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -64,7 +63,6 @@ class Mood extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-2
View File
@@ -15,7 +15,6 @@ class Mucus extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -63,7 +62,6 @@ class Mucus extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-1
View File
@@ -39,7 +39,6 @@ class Note extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-2
View File
@@ -14,7 +14,6 @@ class Pain extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -65,7 +64,6 @@ class Pain extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
-2
View File
@@ -14,7 +14,6 @@ class Sex extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -65,7 +64,6 @@ class Sex extends Component {
<SymptomView <SymptomView
symptom={this.symptom} symptom={this.symptom}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
+22 -42
View File
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { getDate } from '../../../slices/date' import { getDate } from '../../../slices/date'
import { goBack } from '../../../slices/navigation'
import { saveSymptom } from '../../../db' import { saveSymptom } from '../../../db'
import formatDate from '../../helpers/format-date' import formatDate from '../../helpers/format-date'
@@ -16,27 +17,30 @@ import { sharedDialogs } from '../../../i18n/en/cycle-day'
import styles from '../../../styles' import styles from '../../../styles'
const checkIfHasValues = data => {
const isMeaningfulValue = value => value || value === 0
return Object.values(data).some(isMeaningfulValue)
}
class SymptomView extends Component { class SymptomView extends Component {
static propTypes = { static propTypes = {
symptom: PropTypes.string.isRequired, symptom: PropTypes.string.isRequired,
values: PropTypes.object, values: PropTypes.object,
date: PropTypes.string, date: PropTypes.string,
children: PropTypes.node,
goBack: PropTypes.func,
} }
constructor(props) { constructor(props) {
super() super()
this.values = props.values
this.state = { this.state = {
shouldShowDelete: this.checkIfHasValuesToDelete() shouldShowDelete: checkIfHasValues(props.values)
} }
this.date = props.date
this.navigate = props.navigate
} }
componentDidUpdate() { componentDidUpdate() {
this.values = this.props.values const shouldShowDelete = checkIfHasValues(this.props.values)
const shouldShowDelete = this.checkIfHasValuesToDelete()
if (shouldShowDelete !== this.state.shouldShowDelete) { if (shouldShowDelete !== this.state.shouldShowDelete) {
this.setState({ shouldShowDelete }) this.setState({ shouldShowDelete })
} }
@@ -47,39 +51,9 @@ class SymptomView extends Component {
saveSymptom(symptom, date, null) 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 = () => { onDeleteConfirmation = () => {
this.deleteSymptomEntry() this.deleteSymptomEntry()
this.props.handleBackButtonPress() this.props.goBack()
}
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]
)
} }
showConfirmationAlert = () => { showConfirmationAlert = () => {
@@ -102,13 +76,13 @@ class SymptomView extends Component {
} }
render() { render() {
const { symptom } = this.props const { symptom, date, goBack } = this.props
return ( return (
<View style={{flex: 1}}> <View style={{flex: 1}}>
<Header <Header
title={headerTitles[symptom]} title={headerTitles[symptom]}
subtitle={formatDate(this.date)} subtitle={formatDate(date)}
handleBack={this.props.handleBackButtonPress} handleBack={goBack}
handleDelete={ handleDelete={
this.state.shouldShowDelete && this.showConfirmationAlert this.state.shouldShowDelete && this.showConfirmationAlert
} }
@@ -126,11 +100,17 @@ class SymptomView extends Component {
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return({ return({
date: getDate(state) date: getDate(state),
})
}
const mapDispatchToProps = (dispatch) => {
return({
goBack: () => dispatch(goBack()),
}) })
} }
export default connect( export default connect(
mapStateToProps, mapStateToProps,
null mapDispatchToProps,
)(SymptomView) )(SymptomView)
@@ -20,7 +20,6 @@ class Temperature extends Component {
static propTypes = { static propTypes = {
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
handleBackButtonPress: PropTypes.func,
date: PropTypes.string.isRequired, date: PropTypes.string.isRequired,
} }
@@ -90,7 +89,6 @@ class Temperature extends Component {
<SymptomView <SymptomView
symptom={'temperature'} symptom={'temperature'}
values={this.state} values={this.state}
handleBackButtonPress={this.props.handleBackButtonPress}
date={this.props.date} date={this.props.date}
> >
<SymptomSection <SymptomSection
+1 -2
View File
@@ -30,11 +30,10 @@ class Home extends Component {
static propTypes = { static propTypes = {
navigate: PropTypes.func, navigate: PropTypes.func,
setDate: PropTypes.func, setDate: PropTypes.func,
// The following three is not being used, // The following are not being used,
// we could see if it's possible to not pass them from the <App /> // we could see if it's possible to not pass them from the <App />
cycleDay: PropTypes.object, cycleDay: PropTypes.object,
date: PropTypes.string, date: PropTypes.string,
handleBackButtonPress: PropTypes.func,
} }
constructor(props) { constructor(props) {