Merge branch '77-bug-stale-cycle-day-number' into 'master'
Resolve "bug: stale cycle day number" Closes #77 See merge request bloodyhealth/drip!16
This commit is contained in:
+11
-7
@@ -4,16 +4,24 @@ import { Calendar } from 'react-native-calendars'
|
|||||||
import * as styles from './styles'
|
import * as styles from './styles'
|
||||||
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from './db'
|
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from './db'
|
||||||
|
|
||||||
export default class DatePickView extends Component {
|
export default class CalendarView extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
|
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
|
||||||
|
|
||||||
bleedingDaysSortedByDate.addListener(setStateWithCalendarFormattedDays.bind(this))
|
this.setStateWithCalendarFormattedDays = (function (CalendarComponent) {
|
||||||
|
return function() {
|
||||||
|
CalendarComponent.setState({
|
||||||
|
bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})(this)
|
||||||
|
|
||||||
|
bleedingDaysSortedByDate.addListener(this.setStateWithCalendarFormattedDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
bleedingDaysSortedByDate.removeAllListeners()
|
bleedingDaysSortedByDate.removeListener(this.setStateWithCalendarFormattedDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
passDateToDayView(result) {
|
passDateToDayView(result) {
|
||||||
@@ -41,8 +49,4 @@ function getBleedingDaysInCalFormat(bleedingDaysSortedByDate) {
|
|||||||
acc[day.date] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] }
|
acc[day.date] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] }
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
}
|
|
||||||
|
|
||||||
function setStateWithCalendarFormattedDays() {
|
|
||||||
this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
|
|
||||||
}
|
}
|
||||||
+14
-8
@@ -16,11 +16,23 @@ export default class DayView extends Component {
|
|||||||
super(props)
|
super(props)
|
||||||
this.cycleDay = props.cycleDay
|
this.cycleDay = props.cycleDay
|
||||||
this.showView = props.showView
|
this.showView = props.showView
|
||||||
bleedingDaysSortedByDate.addListener(setStateWithCurrentCycleDayNumber.bind(this))
|
this.state = {
|
||||||
|
cycleDayNumber: getCycleDayNumber(this.cycleDay.date),
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setStateWithCurrentCycleDayNumber = (function (DayViewComponent) {
|
||||||
|
return function () {
|
||||||
|
DayViewComponent.setState({
|
||||||
|
cycleDayNumber: getCycleDayNumber(DayViewComponent.cycleDay.date)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})(this)
|
||||||
|
|
||||||
|
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentCycleDayNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
bleedingDaysSortedByDate.removeAllListeners()
|
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentCycleDayNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -56,10 +68,4 @@ export default class DayView extends Component {
|
|||||||
</View >
|
</View >
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function setStateWithCurrentCycleDayNumber() {
|
|
||||||
this.setState({
|
|
||||||
cycleDayNumber: getCycleDayNumber(this.cycleDay.date)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -16,7 +16,6 @@ export default class Day extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.cycleDay = props.navigation.state.params.cycleDay
|
this.cycleDay = props.navigation.state.params.cycleDay
|
||||||
this.cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
visibleComponent: 'dayView',
|
visibleComponent: 'dayView',
|
||||||
@@ -28,10 +27,11 @@ export default class Day extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcome}>{formatDateForViewHeader(this.cycleDay.date)}</Text>
|
<Text style={styles.welcome}>{formatDateForViewHeader(this.cycleDay.date)}</Text>
|
||||||
{ this.cycleDayNumber && <Text>Cycle day {this.cycleDayNumber}</Text> }
|
{ cycleDayNumber && <Text>Cycle day {cycleDayNumber}</Text> }
|
||||||
{
|
{
|
||||||
{ dayView: <DayView cycleDay={this.cycleDay} showView={this.showView} />,
|
{ dayView: <DayView cycleDay={this.cycleDay} showView={this.showView} />,
|
||||||
bleedingEditView: <BleedingEditView cycleDay={this.cycleDay} showView={this.showView}/>,
|
bleedingEditView: <BleedingEditView cycleDay={this.cycleDay} showView={this.showView}/>,
|
||||||
|
|||||||
@@ -21,11 +21,19 @@ export default class Home extends Component {
|
|||||||
welcomeText: determineWelcomeText(cycleDayNumber)
|
welcomeText: determineWelcomeText(cycleDayNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
bleedingDaysSortedByDate.addListener(setStateWithCurrentWelcomeText.bind(this))
|
this.setStateWithCurrentWelcomeText = (function (HomeComponent) {
|
||||||
|
return function () {
|
||||||
|
HomeComponent.setState({
|
||||||
|
welcomeText: determineWelcomeText(getCycleDayNumber(HomeComponent.todayDateString))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})(this)
|
||||||
|
|
||||||
|
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentWelcomeText)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
bleedingDaysSortedByDate.removeAllListeners()
|
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentWelcomeText)
|
||||||
}
|
}
|
||||||
|
|
||||||
passTodayToDayView() {
|
passTodayToDayView() {
|
||||||
@@ -63,6 +71,3 @@ function determineWelcomeText(cycleDayNumber) {
|
|||||||
return cycleDayNumber ? welcomeTextWithCycleDay : welcomeText
|
return cycleDayNumber ? welcomeTextWithCycleDay : welcomeText
|
||||||
}
|
}
|
||||||
|
|
||||||
function setStateWithCurrentWelcomeText() {
|
|
||||||
this.setState({ welcomeText: determineWelcomeText(getCycleDayNumber(this.todayDateString)) })
|
|
||||||
}
|
|
||||||
|
|||||||
Generated
+1561
-1561
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user