Fix peri phase edge case
This commit is contained in:
@@ -9,7 +9,6 @@ import { getCycleDaysSortedByDate } from '../db'
|
|||||||
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
|
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
|
||||||
import styles from '../styles'
|
import styles from '../styles'
|
||||||
import AppText, { AppTextLight } from './app-text'
|
import AppText, { AppTextLight } from './app-text'
|
||||||
import nothingChanged from '../db/db-unchanged'
|
|
||||||
import DripHomeIcon from '../assets/drip-home-icons'
|
import DripHomeIcon from '../assets/drip-home-icons'
|
||||||
|
|
||||||
const HomeButton = ({ backgroundColor, children }) => {
|
const HomeButton = ({ backgroundColor, children }) => {
|
||||||
@@ -42,23 +41,6 @@ export default class Home extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.cycleDays = getCycleDaysSortedByDate()
|
this.cycleDays = getCycleDaysSortedByDate()
|
||||||
this.cycleDays.addListener(this.updateState)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateState = (_, changes) => {
|
|
||||||
if (nothingChanged(changes)) return
|
|
||||||
const prediction = this.getBleedingPrediction()
|
|
||||||
const fertilityStatus = getFertilityStatusForDay(this.todayDateString)
|
|
||||||
this.setState({
|
|
||||||
cycleDayNumber: this.getCycleDayNumber(this.todayDateString),
|
|
||||||
predictionText: determinePredictionText(prediction),
|
|
||||||
bleedingPredictionRange: getBleedingPredictionRange(prediction),
|
|
||||||
...fertilityStatus
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.cycleDays.removeListener(this.updateState)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
passTodayTo(componentName) {
|
passTodayTo(componentName) {
|
||||||
|
|||||||
+23
-11
@@ -1,16 +1,17 @@
|
|||||||
import getFertilityStatus from './sympto'
|
import getFertilityStatus from './sympto'
|
||||||
import cycleModule from './cycle'
|
import cycleModule from './cycle'
|
||||||
import { fertilityStatus } from '../i18n/en/labels'
|
|
||||||
import { useCervixObservable } from '../local-storage'
|
import { useCervixObservable } from '../local-storage'
|
||||||
|
import { fertilityStatus as labels } from '../i18n/en/labels'
|
||||||
|
|
||||||
export function getFertilityStatusForDay(dateString) {
|
export function getFertilityStatusForDay(dateString) {
|
||||||
const status = getCycleStatusForDay(dateString)
|
const status = getCycleStatusForDay(dateString)
|
||||||
if (!status) return {
|
if (!status) return {
|
||||||
status: fertilityStatus.fertile,
|
status: labels.fertile,
|
||||||
phase: null
|
phase: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const phaseNameForDay = Object.keys(status.phases).find(phaseName => {
|
const phases = Object.keys(status.phases)
|
||||||
|
const phaseNameForDay = phases.find(phaseName => {
|
||||||
const phase = status.phases[phaseName]
|
const phase = status.phases[phaseName]
|
||||||
const dayIsAfterPhaseStart = dateString >= phase.start.date
|
const dayIsAfterPhaseStart = dateString >= phase.start.date
|
||||||
let dayIsBeforePhaseEnd
|
let dayIsBeforePhaseEnd
|
||||||
@@ -22,6 +23,12 @@ export function getFertilityStatusForDay(dateString) {
|
|||||||
return dayIsAfterPhaseStart && dayIsBeforePhaseEnd
|
return dayIsAfterPhaseStart && dayIsBeforePhaseEnd
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// if there's only cycle data for the pre phase and the target day is after its end,
|
||||||
|
// the day is in the peri phase
|
||||||
|
if (phases.length === 1 && phases[0] === 'preOvulatory' && !phaseNameForDay) {
|
||||||
|
return formatStatus('periOvulatory', dateString, {phases: {periOvulatory: {}}})
|
||||||
|
}
|
||||||
|
|
||||||
return formatStatus(phaseNameForDay, dateString, status)
|
return formatStatus(phaseNameForDay, dateString, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,27 +65,32 @@ function formatStatus(phaseNameForDay, dateString, status) {
|
|||||||
const mapping = {
|
const mapping = {
|
||||||
preOvulatory: () => {
|
preOvulatory: () => {
|
||||||
return {
|
return {
|
||||||
status: fertilityStatus.infertile,
|
status: labels.infertile,
|
||||||
phase: 1,
|
phase: 1,
|
||||||
statusText: fertilityStatus.preOvuText
|
statusText: labels.preOvuText
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
periOvulatory: (dateString, status) => {
|
periOvulatory: (dateString, status) => {
|
||||||
const phaseEnd = status.phases.periOvulatory.end
|
//there might not actually be any data for the phase
|
||||||
|
const peri = status.phases.periOvulatory
|
||||||
|
const phaseEnd = peri && peri.end
|
||||||
|
let s
|
||||||
if (phaseEnd && phaseEnd.date === dateString) {
|
if (phaseEnd && phaseEnd.date === dateString) {
|
||||||
return fertilityStatus.fertileUntilEvening
|
s = labels.fertileUntilEvening
|
||||||
|
} else {
|
||||||
|
s = labels.fertile
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
status: fertilityStatus.fertile,
|
status: s,
|
||||||
phase: 2,
|
phase: 2,
|
||||||
statusText: fertilityStatus.periOvuText
|
statusText: labels.periOvuText
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
postOvulatory: (dateString, status) => {
|
postOvulatory: (dateString, status) => {
|
||||||
return {
|
return {
|
||||||
status: fertilityStatus.infertile,
|
status: labels.infertile,
|
||||||
phase: 3,
|
phase: 3,
|
||||||
statusText: fertilityStatus.postOvuText(status.temperatureShift.rule)
|
statusText: labels.postOvuText(status.temperatureShift.rule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user