Starts using redux store for storing the date

This commit is contained in:
Sofiya Tepikin
2019-08-04 21:29:14 +02:00
parent 216a9044cd
commit c226923759
19 changed files with 311 additions and 66 deletions
+22 -7
View File
@@ -1,5 +1,9 @@
import React, { Component } from 'react'
import { ScrollView, View } from 'react-native'
import { connect } from 'react-redux'
import { getDate } from '../../slices/date'
import { LocalDate } from 'js-joda'
import Header from '../header'
import FillerBoxes from './FillerBoxes'
@@ -9,18 +13,16 @@ import { getCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import styles from '../../styles'
export default class CycleDayOverView extends Component {
class CycleDayOverView extends Component {
constructor(props) {
super(props)
const { date } = this.props
this.state = {
date,
cycleDay: getCycleDay(date)
cycleDay: getCycleDay(props.date)
}
}
goToCycleDay = (target) => {
const localDate = LocalDate.parse(this.state.date)
const localDate = LocalDate.parse(this.props.date)
const targetDate = target === 'before' ?
localDate.minusDays(1).toString() :
localDate.plusDays(1).toString()
@@ -31,12 +33,14 @@ export default class CycleDayOverView extends Component {
}
navigate(symptom) {
this.props.navigate(symptom, this.state)
this.props.navigate(symptom)
}
render() {
const { date, cycleDay } = this.state
const { getCycleDayNumber } = cycleModule()
const { cycleDay } = this.state
const { date } = this.props
const cycleDayNumber = getCycleDayNumber(date)
const dateInFuture = LocalDate.now().isBefore(LocalDate.parse(date))
@@ -89,3 +93,14 @@ export default class CycleDayOverView extends Component {
)
}
}
const mapStateToProps = (state) => {
return({
date: getDate(state),
})
}
export default connect(
mapStateToProps,
null,
)(CycleDayOverView)