Skip to content
Snippets Groups Projects
Commit e340e89a authored by Julia Friesel's avatar Julia Friesel
Browse files

Update state with calendar format when bleeding days change

parent 2bd0a144
No related branches found
No related tags found
No related merge requests found
...@@ -7,12 +7,11 @@ import { getOrCreateCycleDay, bleedingDaysSortedByDate } from './db' ...@@ -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 { ...@@ -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 { ...@@ -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
}, {})
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment