Update state with calendar format when bleeding days change

This commit is contained in:
Julia Friesel
2018-06-08 18:56:00 +02:00
parent 2bd0a144ec
commit e340e89a0d
+11 -15
View File
@@ -7,12 +7,11 @@ import { getOrCreateCycleDay, bleedingDaysSortedByDate } from './db'
export default class DatePickView extends Component { export default class DatePickView extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
cycleDays: bleedingDaysSortedByDate
}
// so we rerender the calendar when there are new bleeding days // so we rerender the calendar when there are new bleeding days
bleedingDaysSortedByDate.addListener(() => { bleedingDaysSortedByDate.addListener(() => {
this.setState({ cycleDays: bleedingDaysSortedByDate }) this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
}) })
} }
@@ -24,21 +23,12 @@ export default class DatePickView extends Component {
navigate('dayView', { cycleDay }) navigate('dayView', { cycleDay })
} }
rerenderCalendar() {
}
render() { render() {
const bleedingDaysInCalFormat = bleedingDaysSortedByDate.reduce((acc, day) => {
const dateString = day.date.toISOString().slice(0, 10)
acc[dateString] = { startingDay: true, endingDay: true, color: 'red' }
return acc
}, {})
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Calendar <Calendar
onDayPress={ this.passDateToDayView.bind(this) } onDayPress={ this.passDateToDayView.bind(this) }
markedDates = { bleedingDaysInCalFormat } markedDates = { this.state.bleedingDaysInCalFormat }
markingType = {'period'} markingType = {'period'}
/> />
</View> </View>
@@ -46,4 +36,10 @@ export default class DatePickView extends Component {
} }
} }
function getBleedingDaysInCalFormat(bleedingDaysSortedByDate) {
return bleedingDaysSortedByDate.reduce((acc, day) => {
const dateString = day.date.toISOString().slice(0, 10)
acc[dateString] = { startingDay: true, endingDay: true, color: 'red' }
return acc
}, {})
}