From ec907ab23c6702f09bdfa19dcb783a7a8f0337e8 Mon Sep 17 00:00:00 2001
From: Sofiya Tepikin <sofiya.tepikin@gmail.com>
Date: Sat, 29 Feb 2020 12:55:58 +0100
Subject: [PATCH] Gets rid of the redundant state on Home

---
 components/home.js | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/components/home.js b/components/home.js
index 1f898483..fa98ac51 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
-    }
+    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 (
       <View flex={1}>
         <ScrollView>
@@ -92,11 +96,11 @@ class Home extends Component {
               <DripHomeIcon name="drop" size={100} color={periodColor} />
 
               <IconText wrapperStyles={{ top: '45%' }}>
-                {this.state.bleedingPredictionRange}
+                {bleedingPredictionRange}
               </IconText>
 
               <AppText style={styles.homeDescriptionText}>
-                {this.state.predictionText}
+                {predictionText}
               </AppText>
             </HomeElement>
 
-- 
GitLab