Refactor getStatusAsString
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
|||||||
Text
|
Text
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import cycleModule from '../../lib/cycle'
|
import cycleModule from '../../lib/cycle'
|
||||||
import getFertilityStatus from '../../lib/sympto-adapter'
|
import { getFertilityStatusStringForDay } from '../../lib/sympto-adapter'
|
||||||
import DayView from './cycle-day-overview'
|
import DayView from './cycle-day-overview'
|
||||||
import BleedingEditView from './symptoms/bleeding'
|
import BleedingEditView from './symptoms/bleeding'
|
||||||
import TemperatureEditView from './symptoms/temperature'
|
import TemperatureEditView from './symptoms/temperature'
|
||||||
@@ -33,7 +33,7 @@ export default class Day extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
const cycleDayNumber = getCycleDayNumber(this.cycleDay.date)
|
||||||
const fertilityStatus = getFertilityStatus(this.cycleDay.date)
|
const fertilityStatus = getFertilityStatusStringForDay(this.cycleDay.date)
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<View style={ styles.cycleDayDateView }>
|
<View style={ styles.cycleDayDateView }>
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export default class Mucus extends Component {
|
|||||||
saveSymptom('mucus', this.cycleDay, {
|
saveSymptom('mucus', this.cycleDay, {
|
||||||
feeling: this.state.currentFeelingValue,
|
feeling: this.state.currentFeelingValue,
|
||||||
texture: this.state.currentTextureValue,
|
texture: this.state.currentTextureValue,
|
||||||
computedNfp: computeSensiplanValue(this.state.currentFeelingValue, this.state.currentTextureValue),
|
value: computeSensiplanValue(this.state.currentFeelingValue, this.state.currentTextureValue),
|
||||||
exclude: this.state.exclude
|
exclude: this.state.exclude
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
+44
-16
@@ -2,31 +2,59 @@ import getFertilityStatus from './sympto'
|
|||||||
import cycleModule from './cycle'
|
import cycleModule from './cycle'
|
||||||
import { fertilityStatus } from '../labels/labels'
|
import { fertilityStatus } from '../labels/labels'
|
||||||
|
|
||||||
const { getCycleDaysBeforeDay, getPreviousCycles } = cycleModule()
|
const {
|
||||||
|
getCycleForDay,
|
||||||
|
getCyclesBefore,
|
||||||
|
getPreviousCycle
|
||||||
|
} = cycleModule()
|
||||||
|
|
||||||
export default function (dateString) {
|
export function getFertilityStatusStringForDay(dateString) {
|
||||||
const cycle = getCycleDaysBeforeDay(dateString)
|
const cycle = getCycleForDay(dateString)
|
||||||
if (!cycle) return fertilityStatus.unknown
|
if (!cycle) return fertilityStatus.unknown
|
||||||
|
|
||||||
const previousCycles = getPreviousCycles(cycle[0])
|
const cycleInfo = {cycle: formatCycleForSympto(cycle)}
|
||||||
|
|
||||||
const status = getFertilityStatus({
|
const previousCycle = getPreviousCycle(dateString)
|
||||||
cycle: formatCycleForSympto(cycle),
|
|
||||||
previousCycles: previousCycles.map(formatCycleForSympto)
|
if (previousCycle) {
|
||||||
|
cycleInfo.previousCycle = formatCycleForSympto(previousCycle)
|
||||||
|
const earlierCycles = getCyclesBefore(previousCycle[0])
|
||||||
|
if (earlierCycles) {
|
||||||
|
cycleInfo.earlierCycles = earlierCycles.map(formatCycleForSympto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = getFertilityStatus(cycleInfo)
|
||||||
|
|
||||||
|
const phaseNameForDay = Object.keys(status.phases).find(phaseName => {
|
||||||
|
const phase = status.phases[phaseName]
|
||||||
|
const dayIsAfterPhaseStart = dateString >= phase.start.date
|
||||||
|
let dayIsBeforePhaseEnd
|
||||||
|
if (phase.end) {
|
||||||
|
dayIsBeforePhaseEnd = dateString <= phase.end.date
|
||||||
|
} else {
|
||||||
|
dayIsBeforePhaseEnd = true
|
||||||
|
}
|
||||||
|
return dayIsAfterPhaseStart && dayIsBeforePhaseEnd
|
||||||
})
|
})
|
||||||
|
|
||||||
if (status.phases.postOvulatory) {
|
return mapToString(phaseNameForDay, dateString, status)
|
||||||
const phase = status.phases.postOvulatory
|
|
||||||
if (phase.start.date === dateString) {
|
|
||||||
return fertilityStatus.fertileUntilEvening
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.assumeFertility) {
|
function mapToString(phaseNameForDay, dateString, status) {
|
||||||
return fertilityStatus.fertile
|
const mapping = {
|
||||||
} else {
|
preOvulatory: () => fertilityStatus.infertile,
|
||||||
return fertilityStatus.infertile
|
periOvulatory: (dateString, status) => {
|
||||||
|
const phaseEnd = status.phases.periOvulatory.end
|
||||||
|
if (phaseEnd && phaseEnd.date === dateString) {
|
||||||
|
return fertilityStatus.fertileUntilEvening
|
||||||
}
|
}
|
||||||
|
return fertilityStatus.fertile
|
||||||
|
},
|
||||||
|
postOvulatory: () => fertilityStatus.infertile
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapping[phaseNameForDay](dateString, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCycleForSympto(cycle) {
|
function formatCycleForSympto(cycle) {
|
||||||
|
|||||||
Reference in New Issue
Block a user