Gets rid of the redundant state on Home

This commit is contained in:
Sofiya Tepikin
2020-02-29 12:55:58 +01:00
parent d5b1944988
commit ec907ab23c
+21 -17
View File
@@ -25,21 +25,20 @@ import {
import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles' import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles'
class Home extends Component { class Home extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
const { getCycleDayNumber, getPredictedMenses } = cycleModule()
this.getCycleDayNumber = getCycleDayNumber
this.getBleedingPrediction = getPredictedMenses
this.todayDateString = LocalDate.now().toString()
const prediction = this.getBleedingPrediction()
const fertilityStatus = getFertilityStatusForDay(this.todayDateString)
this.state = { const { getCycleDayNumber, getPredictedMenses } = cycleModule()
cycleDayNumber: this.getCycleDayNumber(this.todayDateString),
predictionText: determinePredictionText(prediction), this.todayDateString = LocalDate.now().toString()
bleedingPredictionRange: getBleedingPredictionRange(prediction), this.cycleDayNumber = getCycleDayNumber(this.todayDateString)
...fertilityStatus
} const prediction = getPredictedMenses()
this.predictionText = determinePredictionText(prediction)
this.bleedingPredictionRange = getBleedingPredictionRange(prediction)
this.fertilityStatus = getFertilityStatusForDay(this.todayDateString)
} }
navigateToCycleDayView = () => { navigateToCycleDayView = () => {
@@ -57,13 +56,18 @@ class Home extends Component {
} }
render() { render() {
const { cycleDayNumber, phase, status } = this.state const {
cycleDayNumber,
predictionText,
bleedingPredictionRange,
} = this
const { phase, status, statusText } = this.fertilityStatus
const cycleDayMoreText = cycleDayNumber ? const cycleDayMoreText = cycleDayNumber ?
labels.cycleDayKnown(cycleDayNumber) : labels.cycleDayKnown(cycleDayNumber) :
labels.cycleDayNotEnoughInfo labels.cycleDayNotEnoughInfo
const { statusText } = this.state
return ( return (
<View flex={1}> <View flex={1}>
<ScrollView> <ScrollView>
@@ -92,11 +96,11 @@ class Home extends Component {
<DripHomeIcon name="drop" size={100} color={periodColor} /> <DripHomeIcon name="drop" size={100} color={periodColor} />
<IconText wrapperStyles={{ top: '45%' }}> <IconText wrapperStyles={{ top: '45%' }}>
{this.state.bleedingPredictionRange} {bleedingPredictionRange}
</IconText> </IconText>
<AppText style={styles.homeDescriptionText}> <AppText style={styles.homeDescriptionText}>
{this.state.predictionText} {predictionText}
</AppText> </AppText>
</HomeElement> </HomeElement>