From ec907ab23c6702f09bdfa19dcb783a7a8f0337e8 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Sat, 29 Feb 2020 12:55:58 +0100 Subject: [PATCH] Gets rid of the redundant state on Home --- components/home.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/components/home.js b/components/home.js index 1f89848..fa98ac5 100644 --- a/components/home.js +++ b/components/home.js @@ -25,21 +25,20 @@ import { import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles' class Home extends Component { + constructor(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 = { - cycleDayNumber: this.getCycleDayNumber(this.todayDateString), - predictionText: determinePredictionText(prediction), - bleedingPredictionRange: getBleedingPredictionRange(prediction), - ...fertilityStatus - } + const { getCycleDayNumber, getPredictedMenses } = cycleModule() + + this.todayDateString = LocalDate.now().toString() + this.cycleDayNumber = getCycleDayNumber(this.todayDateString) + + const prediction = getPredictedMenses() + this.predictionText = determinePredictionText(prediction) + this.bleedingPredictionRange = getBleedingPredictionRange(prediction) + + this.fertilityStatus = getFertilityStatusForDay(this.todayDateString) } navigateToCycleDayView = () => { @@ -57,13 +56,18 @@ class Home extends Component { } render() { - const { cycleDayNumber, phase, status } = this.state + const { + cycleDayNumber, + predictionText, + bleedingPredictionRange, + } = this + + const { phase, status, statusText } = this.fertilityStatus + const cycleDayMoreText = cycleDayNumber ? labels.cycleDayKnown(cycleDayNumber) : labels.cycleDayNotEnoughInfo - const { statusText } = this.state - return ( @@ -92,11 +96,11 @@ class Home extends Component { - {this.state.bleedingPredictionRange} + {bleedingPredictionRange} - {this.state.predictionText} + {predictionText}