information about bleeding data is shown on home screen
This commit is contained in:
+34
-6
@@ -5,10 +5,11 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
ScrollView
|
ScrollView
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate, ChronoUnit } from 'js-joda'
|
||||||
import styles from '../styles/index'
|
import styles from '../styles/index'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
|
import { getOrCreateCycleDay, bleedingDaysSortedByDate, fillWithDummyData, deleteAll } from '../db'
|
||||||
|
import {bleedingPrediction as labels} from './labels'
|
||||||
|
|
||||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||||
|
|
||||||
@@ -19,23 +20,25 @@ export default class Home extends Component {
|
|||||||
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
welcomeText: determineWelcomeText(cycleDayNumber)
|
welcomeText: determineWelcomeText(cycleDayNumber),
|
||||||
|
predictionText: determinePredictionText()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setStateWithCurrentWelcomeText = (function (HomeComponent) {
|
this.setStateWithCurrentText = (function (HomeComponent) {
|
||||||
return function () {
|
return function () {
|
||||||
const cycleDayNumber = getCycleDayNumber(HomeComponent.todayDateString)
|
const cycleDayNumber = getCycleDayNumber(HomeComponent.todayDateString)
|
||||||
HomeComponent.setState({
|
HomeComponent.setState({
|
||||||
welcomeText: determineWelcomeText(cycleDayNumber)
|
welcomeText: determineWelcomeText(cycleDayNumber),
|
||||||
|
predictionText: determinePredictionText()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})(this)
|
})(this)
|
||||||
|
|
||||||
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentWelcomeText)
|
bleedingDaysSortedByDate.addListener(this.setStateWithCurrentText)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentWelcomeText)
|
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentText)
|
||||||
}
|
}
|
||||||
|
|
||||||
passTodayToDayView() {
|
passTodayToDayView() {
|
||||||
@@ -49,6 +52,7 @@ export default class Home extends Component {
|
|||||||
return (
|
return (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
|
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
|
||||||
|
<Text style={styles.welcome}>{this.state.predictionText}</Text>
|
||||||
<View style={styles.homeButtons}>
|
<View style={styles.homeButtons}>
|
||||||
<View style={styles.homeButton}>
|
<View style={styles.homeButton}>
|
||||||
<Button
|
<Button
|
||||||
@@ -80,3 +84,27 @@ function determineWelcomeText(cycleDayNumber) {
|
|||||||
return cycleDayNumber ? welcomeTextWithCycleDay : welcomeText
|
return cycleDayNumber ? welcomeTextWithCycleDay : welcomeText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function determinePredictionText() {
|
||||||
|
const bleedingPrediction = cycleModule().getPredictedMenses()
|
||||||
|
if (!bleedingPrediction.length) return labels.noPrediction
|
||||||
|
const todayDate = LocalDate.now()
|
||||||
|
const bleedingStart = LocalDate.parse(bleedingPrediction[0][0])
|
||||||
|
const bleedingEnd = LocalDate.parse(bleedingPrediction[0][ bleedingPrediction[0].length - 1 ])
|
||||||
|
if (todayDate.isBefore(bleedingStart)) {
|
||||||
|
return labels.predictionInFuture(
|
||||||
|
todayDate.until(bleedingStart, ChronoUnit.DAYS),
|
||||||
|
todayDate.until(bleedingEnd, ChronoUnit.DAYS)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (todayDate.isAfter(bleedingEnd)) {
|
||||||
|
return labels.predictionInPast(bleedingStart.toString(), bleedingEnd.toString())
|
||||||
|
}
|
||||||
|
const daysToEnd = todayDate.until(bleedingEnd, ChronoUnit.DAYS)
|
||||||
|
if (daysToEnd === 0) {
|
||||||
|
return labels.predictionStartedNoDaysLeft
|
||||||
|
} else if (daysToEnd === 1) {
|
||||||
|
return labels.predictionStarted1DayLeft
|
||||||
|
} else {
|
||||||
|
return labels.predictionStartedXDaysLeft(daysToEnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,3 +57,12 @@ export const stats = {
|
|||||||
maxLabel: 'Longest cycle',
|
maxLabel: 'Longest cycle',
|
||||||
stdLabel: 'Standard deviation'
|
stdLabel: 'Standard deviation'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const bleedingPrediction = {
|
||||||
|
noPrediction: 'There is not enough period data to predict the next one.',
|
||||||
|
predictionInFuture: (startDays, endDays) => `Your next period is likely to start in ${startDays} to ${endDays} days.`,
|
||||||
|
predictionStartedXDaysLeft: (numberOfDays) => `Your period is likely to start today or during the next ${numberOfDays} days.`,
|
||||||
|
predictionStarted1DayLeft: 'Your period is likely to start today or tomorrow.',
|
||||||
|
predictionStartedNoDaysLeft: 'Your period is likely to start today.',
|
||||||
|
predictionInPast: (startDate, endDate) => `Based on your documented data, your period was likely to start between ${startDate} and ${endDate}.`
|
||||||
|
}
|
||||||
Generated
+1545
-1545
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user