From aa2165590b9ab0fafdaf27d84137afe3c81948de Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Wed, 26 Feb 2020 21:08:26 +0100 Subject: [PATCH 1/3] Removes redundant state and corrects the cycle day prop --- components/app.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/components/app.js b/components/app.js index a351513..ee84c5b 100644 --- a/components/app.js +++ b/components/app.js @@ -2,7 +2,6 @@ import React, { Component } from 'react' import { View, BackHandler } from 'react-native' import PropTypes from 'prop-types' -import { LocalDate } from 'js-joda' import { connect } from 'react-redux' import { getDate, setDate } from '../slices/date' @@ -27,13 +26,6 @@ class App extends Component { constructor(props) { super(props) - this.todayDateString = LocalDate.now().toString() - props.setDate(this.todayDateString) - - this.state = { - cycleDay: getCycleDay(this.todayDateString), - } - this.backHandler = BackHandler.addEventListener( 'hardwareBackPress', props.goBack @@ -54,8 +46,6 @@ class App extends Component { return false } - const { cycleDay } = this.state - const Page = viewsList[currentPage] const title = headerTitles[currentPage] @@ -69,7 +59,7 @@ class App extends Component { } const pageProps = { - cycleDay, + cycleDay: date && getCycleDay(date), date, handleBackButtonPress: goBack, } @@ -108,4 +98,4 @@ const mapDispatchToProps = (dispatch) => { export default connect( mapStateToProps, mapDispatchToProps -)(App) \ No newline at end of file +)(App) From f789a7990ffbe66fccca5bcf3ca9f77d4a15b910 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Wed, 26 Feb 2020 21:08:59 +0100 Subject: [PATCH 2/3] Sets initial value of date in the store --- slices/date.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slices/date.js b/slices/date.js index 84ad7b1..49dfa70 100644 --- a/slices/date.js +++ b/slices/date.js @@ -1,8 +1,9 @@ import { createSlice } from 'redux-starter-kit' +import { LocalDate } from 'js-joda' const dateSlice = createSlice({ slice: 'date', - initialState: null, + initialState: LocalDate.now().toString(), reducers: { setDate: (state, action) => action.payload } From 1c0c2276de635ed0a7ef589b96357b8db117c79c Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Wed, 26 Feb 2020 21:09:52 +0100 Subject: [PATCH 3/3] Resets the date in store for today date when navigating home --- components/home.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/home.js b/components/home.js index 497007c..69604b0 100644 --- a/components/home.js +++ b/components/home.js @@ -4,6 +4,7 @@ import { ScrollView, View } from 'react-native' import { connect } from 'react-redux' import { navigate } from '../slices/navigation' +import { setDate } from '../slices/date' import DripHomeIcon from '../assets/drip-home-icons' import { @@ -71,10 +72,12 @@ class Home extends Component { } navigateToCycleDayView = () => { + this.props.setDate(this.todayDateString) this.props.navigate('CycleDay') } navigateToBleedingEditView = () => { + this.props.setDate(this.todayDateString) this.props.navigate('BleedingEditView') } @@ -157,7 +160,8 @@ class Home extends Component { const mapDispatchToProps = (dispatch) => { return({ - navigate: (page) => dispatch(navigate(page)) + navigate: (page) => dispatch(navigate(page)), + setDate: (date) => dispatch(setDate(date)), }) }