Starts using redux store for storing the date
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user