Replace getOrCreateCycleDay

This commit is contained in:
Julia Friesel
2018-11-16 14:24:16 +01:00
parent ecca6cfda9
commit bb0a535d65
18 changed files with 255 additions and 309 deletions
+1 -2
View File
@@ -56,8 +56,7 @@ export default class App extends Component {
if (this.state.currentPage === 'Home') return false
if (isSymptomView(this.state.currentPage)) {
this.navigate(
this.originForSymptomView,
{ cycleDay: this.state.currentProps.cycleDay }
this.originForSymptomView, { date: this.state.currentProps.date }
)
} else if(this.state.currentPage === 'CycleDay') {
this.navigate(this.menuOrigin)
+2 -3
View File
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import { CalendarList } from 'react-native-calendars'
import {LocalDate} from 'js-joda'
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
import { getBleedingDaysSortedByDate } from '../db'
import cycleModule from '../lib/cycle'
import {shadesOfRed} from '../styles/index'
import styles from '../styles/index'
@@ -36,9 +36,8 @@ export default class CalendarView extends Component {
}
passDateToDayView = (result) => {
const cycleDay = getOrCreateCycleDay(result.dateString)
const navigate = this.props.navigate
navigate('CycleDay', { cycleDay })
navigate('CycleDay', { date: result.dateString })
}
render() {
return (
+3 -9
View File
@@ -7,7 +7,6 @@ import { LocalDate } from 'js-joda'
import moment from 'moment'
import styles from './styles'
import config from '../../config'
import { getOrCreateCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import { getCycleDay } from '../../db'
import DotAndLine from './dot-and-line'
@@ -58,13 +57,8 @@ export default class DayColumn extends Component {
)
}
passDateToDayView(dateString) {
const cycleDay = getOrCreateCycleDay(dateString)
this.props.navigate('CycleDay', { cycleDay })
}
shouldComponentUpdate(newProps) {
return Object.keys(newProps).some(key => newProps[key] != this.props[key])
shouldComponentUpdate() {
return false
}
render() {
@@ -232,7 +226,7 @@ export default class DayColumn extends Component {
return (
<TouchableOpacity
onPress={() => this.passDateToDayView(dateString)}
onPress={() => this.props.navigate('CycleDay', { date: dateString })}
activeOpacity={1}
>
<View>
+129 -117
View File
@@ -8,7 +8,7 @@ import {
import { LocalDate } from 'js-joda'
import Svg, { G } from 'react-native-svg'
import Header from '../header'
import { getOrCreateCycleDay } from '../../db'
import { getCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import styles from '../../styles'
import * as labels from './labels'
@@ -29,44 +29,151 @@ const openingLabels = labels.cervix.opening.categories
const firmnessLabels = labels.cervix.firmness.categories
const positionLabels = labels.cervix.position.categories
const intensityLabels = labels.intensity
const sexLabels = labels.sex
const sexLabels = labels.sex.categories
const contraceptiveLabels = labels.contraceptives.categories
const painLabels = labels.pain.categories
export default class CycleDayOverView extends Component {
constructor(props) {
super(props)
this.state = {
cycleDay: props.cycleDay
date: this.props.date,
cycleDay: getCycleDay(this.props.date)
}
}
goToCycleDay = (target) => {
const localDate = LocalDate.parse(this.state.cycleDay.date)
const localDate = LocalDate.parse(this.state.date)
const targetDate = target === 'before' ?
localDate.minusDays(1).toString() :
localDate.plusDays(1).toString()
this.setState({ cycleDay: getOrCreateCycleDay(targetDate) })
}
navigate(symptom) {
this.props.navigate(symptom, {
cycleDay: this.state.cycleDay,
this.setState({
date: targetDate,
cycleDay: getCycleDay(targetDate)
})
}
render() {
navigate(symptom) {
this.props.navigate(symptom, this.state)
}
getLabel(symptomName) {
const cycleDay = this.state.cycleDay
if (!cycleDay || !cycleDay[symptomName]) return
const l = {
bleeding: bleeding => {
if (isNumber(bleeding.value)) {
let bleedingLabel = `${bleedingLabels[bleeding.value]}`
if (bleeding.exclude) bleedingLabel = "( " + bleedingLabel + " )"
return bleedingLabel
}
},
temperature: temperature => {
if (isNumber(temperature.value)) {
let temperatureLabel = `${temperature.value} °C - ${temperature.time}`
if (temperature.exclude) {
temperatureLabel = "( " + temperatureLabel + " )"
}
return temperatureLabel
}
},
mucus: mucus => {
const categories = ['feeling', 'texture', 'value']
if (categories.every(c => isNumber(mucus[c]))) {
let mucusLabel = [feelingLabels[mucus.feeling], textureLabels[mucus.texture]].join(', ')
mucusLabel += `\n${labels.mucusNFP[mucus.value]}`
if (mucus.exclude) mucusLabel = `(${mucusLabel})`
return mucusLabel
}
},
cervix: cervix => {
let cervixLabel = []
if (isNumber(cervix.opening) && isNumber(cervix.firmness)) {
cervixLabel.push(
openingLabels[cervix.opening],
firmnessLabels[cervix.firmness]
)
if (isNumber(cervix.position)) {
cervixLabel.push(positionLabels[cervix.position])
}
cervixLabel = cervixLabel.join(', ')
if (cervix.exclude) cervixLabel = `(${cervixLabel})`
return cervixLabel
}
},
note: note => {
return note.value
},
desire: desire => {
if (isNumber(desire.value)) {
const desireLabel = `${intensityLabels[desire.value]}`
return desireLabel
}
},
sex: sex => {
let sexLabel = []
if (sex && Object.values(sex).some(val => val)){
Object.keys(sex).forEach(key => {
if(sex[key] && key !== 'other' && key !== 'note') {
sexLabel.push(
sexLabels[key] ||
contraceptiveLabels[key]
)
}
if(key === 'other' && sex.other) {
let label = contraceptiveLabels[key]
if(sex.note) {
label = `${label} (${sex.note})`
}
sexLabel.push(label)
}
})
sexLabel = sexLabel.join(', ')
return sexLabel
}
},
pain: pain => {
let painLabel = []
if (pain && Object.values(pain).some(val => val)){
Object.keys(pain).forEach(key => {
if(pain[key] && key !== 'other' && key !== 'note') {
painLabel.push(painLabels[key])
}
if(key === 'other' && pain.other) {
let label = painLabels[key]
if(pain.note) {
label = `${label} (${pain.note})`
}
painLabel.push(label)
}
})
painLabel = painLabel.join(', ')
return painLabel
}
}
}
const symptomValue = cycleDay[symptomName]
const label = l[symptomName](symptomValue)
if (!label) return
if (label.length < 45) return label
return label.slice(0, 42) + '...'
}
render() {
const getCycleDayNumber = cycleModule().getCycleDayNumber
const cycleDayNumber = getCycleDayNumber(cycleDay.date)
const cycleDayNumber = getCycleDayNumber(this.state.date)
const dateInFuture = LocalDate
.now()
.isBefore(LocalDate.parse(this.state.cycleDay.date))
.isBefore(LocalDate.parse(this.state.date))
return (
<View style={{ flex: 1 }}>
<Header
isCycleDayOverView={true}
cycleDayNumber={cycleDayNumber}
date={cycleDay.date}
date={this.state.date}
goToCycleDay={this.goToCycleDay}
/>
<ScrollView>
@@ -74,7 +181,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Bleeding'
onPress={() => this.navigate('BleedingEditView')}
data={getLabel('bleeding', cycleDay.bleeding)}
data={this.getLabel('bleeding')}
disabled={dateInFuture}
>
<BleedingIcon viewBox='10 10 320 400' />
@@ -82,7 +189,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Temperature'
onPress={() => this.navigate('TemperatureEditView')}
data={getLabel('temperature', cycleDay.temperature)}
data={this.getLabel('temperature')}
disabled={dateInFuture}
>
<TemperatureIcon viewBox='10 10 320 400' />
@@ -90,7 +197,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Mucus'
onPress={() => this.navigate('MucusEditView')}
data={getLabel('mucus', cycleDay.mucus)}
data={this.getLabel('mucus')}
disabled={dateInFuture}
>
<MucusIcon viewBox='10 10 320 400' />
@@ -98,7 +205,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Cervix'
onPress={() => this.navigate('CervixEditView')}
data={getLabel('cervix', cycleDay.cervix)}
data={this.getLabel('cervix')}
disabled={dateInFuture}
>
<CervixIcon viewBox='10 10 320 440' />
@@ -106,7 +213,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Desire'
onPress={() => this.navigate('DesireEditView')}
data={getLabel('desire', cycleDay.desire)}
data={this.getLabel('desire')}
disabled={dateInFuture}
>
<DesireIcon viewBox='10 10 320 380' />
@@ -114,7 +221,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Sex'
onPress={() => this.navigate('SexEditView')}
data={getLabel('sex', cycleDay.sex)}
data={this.getLabel('sex')}
disabled={dateInFuture}
>
<SexIcon viewBox='10 10 320 400' />
@@ -122,7 +229,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Pain'
onPress={() => this.navigate('PainEditView')}
data={getLabel('pain', cycleDay.pain)}
data={this.getLabel('pain')}
disabled={dateInFuture}
>
<PainIcon viewBox='10 10 300 400' />
@@ -130,7 +237,7 @@ export default class CycleDayOverView extends Component {
<SymptomBox
title='Note'
onPress={() => this.navigate('NoteEditView')}
data={getLabel('note', cycleDay.note)}
data={this.getLabel('note')}
>
<NoteIcon viewBox='10 10 270 400' />
</SymptomBox>
@@ -144,102 +251,7 @@ export default class CycleDayOverView extends Component {
}
}
function getLabel(symptomName, symptom) {
const l = {
bleeding: bleeding => {
if (isNumber(bleeding.value)) {
let bleedingLabel = `${bleedingLabels[bleeding.value]}`
if (bleeding.exclude) bleedingLabel = "( " + bleedingLabel + " )"
return bleedingLabel
}
},
temperature: temperature => {
if (isNumber(temperature.value)) {
let temperatureLabel = `${temperature.value} °C - ${temperature.time}`
if (temperature.exclude) {
temperatureLabel = "( " + temperatureLabel + " )"
}
return temperatureLabel
}
},
mucus: mucus => {
const categories = ['feeling', 'texture', 'value']
if (categories.every(c => isNumber(mucus[c]))) {
let mucusLabel = [feelingLabels[mucus.feeling], textureLabels[mucus.texture]].join(', ')
mucusLabel += `\n${labels.mucusNFP[mucus.value]}`
if (mucus.exclude) mucusLabel = `(${mucusLabel})`
return mucusLabel
}
},
cervix: cervix => {
let cervixLabel = []
if (isNumber(cervix.opening) && isNumber(cervix.firmness)) {
cervixLabel.push(
openingLabels[cervix.opening],
firmnessLabels[cervix.firmness]
)
if (isNumber(cervix.position)) {
cervixLabel.push(positionLabels[cervix.position])
}
cervixLabel = cervixLabel.join(', ')
if (cervix.exclude) cervixLabel = `(${cervixLabel})`
return cervixLabel
}
},
note: note => {
return note.value
},
desire: desire => {
if (isNumber(desire.value)) {
const desireLabel = `${intensityLabels[desire.value]}`
return desireLabel
}
},
sex: sex => {
let sexLabel = []
if (sex && Object.values(sex).some(val => val)){
Object.keys(sex).forEach(key => {
if(sex[key] && key !== 'other' && key !== 'note') {
sexLabel.push(sexLabels[key])
}
if(key === 'other' && sex.other) {
let label = sexLabels[key]
if(sex.note) {
label = `${label} (${sex.note})`
}
sexLabel.push(label)
}
})
sexLabel = sexLabel.join(', ')
}
return sexLabel
},
pain: pain => {
let painLabel = []
if (pain && Object.values(pain).some(val => val)){
Object.keys(pain).forEach(key => {
if(pain[key] && key !== 'other' && key !== 'note') {
painLabel.push(painLabels[key])
}
if(key === 'other' && pain.other) {
let label = painLabels[key]
if(pain.note) {
label = `${label} (${pain.note})`
}
painLabel.push(label)
}
})
painLabel = painLabel.join(', ')
}
return painLabel
}
}
if (!symptom) return
const label = l[symptomName](symptom)
if (label.length < 45) return label
return label.slice(0, 42) + '...'
}
class SymptomBox extends Component {
+21 -15
View File
@@ -35,19 +35,26 @@ export const desire = {
}
export const sex = {
solo: 'Solo',
partner: 'Partner',
condom: 'Condom',
pill: 'Pill',
iud: 'IUD',
patch: 'Patch',
ring: 'Ring',
implant: 'Implant',
diaphragm: 'Diaphragm',
none: 'None',
other: 'Other',
activityExplainer: 'Were you sexually active today?',
contraceptiveExplainer: 'Did you use contraceptives?'
categories:{
solo: 'Solo',
partner: 'Partner',
},
explainer: 'Were you sexually active today?',
}
export const contraceptives = {
categories:{
condom: 'Condom',
pill: 'Pill',
iud: 'IUD',
patch: 'Patch',
ring: 'Ring',
implant: 'Implant',
diaphragm: 'Diaphragm',
none: 'None',
other: 'Other',
},
explainer: 'Did you use contraceptives?'
}
export const pain = {
@@ -59,8 +66,7 @@ export const pain = {
nausea: 'Nausea',
tenderBreasts: 'Tender breasts',
migraine: 'Migraine',
other: 'Other',
note: 'Note',
other: 'Other'
},
explainer: 'How did your body feel today?'
}
+5 -5
View File
@@ -10,20 +10,20 @@ export default class SelectBoxGroup extends Component {
render() {
return (
<View style={styles.selectBoxSection}>
{this.props.data.map(({ label, stateKey }) => {
{Object.keys(this.props.labels).map(key => {
const style = [styles.selectBox]
const textStyle = []
if (this.props.optionsState[stateKey]) {
if (this.props.optionsState[key]) {
style.push(styles.selectBoxActive)
textStyle.push(styles.selectBoxTextActive)
}
return (
<TouchableOpacity
onPress={() => this.props.onSelect(stateKey)}
key={stateKey}
onPress={() => this.props.onSelect(key)}
key={key}
>
<View style={style}>
<AppText style={textStyle}>{label}</AppText>
<AppText style={textStyle}>{this.props.labels[key]}</AppText>
</View>
</TouchableOpacity>
)
@@ -11,13 +11,14 @@ export default class ActionButtonFooter extends Component {
render() {
const {
symptom,
cycleDay,
currentSymptomValue,
date,
saveAction,
saveDisabled,
navigate,
autoShowDayView = true}
= this.props
const navigateToOverView = () => navigate('CycleDay', {cycleDay})
const navigateToOverView = () => navigate('CycleDay', {date})
const buttons = [
{
title: labels.unset,
@@ -31,13 +32,13 @@ export default class ActionButtonFooter extends Component {
}, {
text: labels.reallyUnsetData,
onPress: () => {
saveSymptom(symptom, cycleDay)
saveSymptom(symptom, date)
navigateToOverView()
}
}]
)
},
disabledCondition: !cycleDay[symptom],
disabledCondition: !currentSymptomValue,
icon: 'delete-outline'
}, {
title: labels.save,
+7 -5
View File
@@ -14,11 +14,12 @@ import SymptomSection from './symptom-section'
export default class Bleeding extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.bleeding = cycleDay && cycleDay.bleeding
this.makeActionButtons = props.makeActionButtons
this.state = {
currentValue: this.cycleDay.bleeding && this.cycleDay.bleeding.value,
exclude: this.cycleDay.bleeding ? this.cycleDay.bleeding.exclude : false
currentValue: this.bleeding && this.bleeding.value,
exclude: this.bleeding ? this.bleeding.exclude : false
}
}
@@ -57,9 +58,10 @@ export default class Bleeding extends Component {
</ScrollView>
<ActionButtonFooter
symptom='bleeding'
cycleDay={this.props.cycleDay}
date={this.props.date}
currentSymptomValue={this.bleeding}
saveAction={() => {
saveSymptom('bleeding', this.props.cycleDay, {
saveSymptom('bleeding', this.props.date, {
value: this.state.currentValue,
exclude: this.state.exclude
})
+7 -10
View File
@@ -14,14 +14,10 @@ import SymptomSection from './symptom-section'
export default class Cervix extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.cervix = cycleDay && cycleDay.cervix
this.makeActionButtons = props.makeActionButtons
this.state = {
exclude: this.cycleDay.cervix ? this.cycleDay.cervix.exclude : false,
opening: this.cycleDay.cervix ? this.cycleDay.cervix.opening : null,
firmness: this.cycleDay.cervix ? this.cycleDay.cervix.firmness : null,
position: this.cycleDay.cervix ? this.cycleDay.cervix.position : null
}
this.state = this.cervix ? this.cervix : {}
}
render() {
@@ -87,13 +83,14 @@ export default class Cervix extends Component {
</ScrollView>
<ActionButtonFooter
symptom='cervix'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.cervix}
saveAction={() => {
saveSymptom('cervix', this.cycleDay, {
saveSymptom('cervix', this.props.date, {
opening: this.state.opening,
firmness: this.state.firmness,
position: this.state.position,
exclude: this.state.exclude
exclude: Boolean(this.state.exclude)
})
}}
saveDisabled={typeof this.state.opening != 'number' || typeof this.state.firmness != 'number'}
+6 -4
View File
@@ -13,9 +13,10 @@ import SymptomSection from './symptom-section'
export default class Desire extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.desire = cycleDay && cycleDay.desire
this.makeActionButtons = props.makeActionButtons
const desireValue = this.cycleDay.desire && this.cycleDay.desire.value
const desireValue = this.desire && this.desire.value
this.state = { currentValue: desireValue }
}
@@ -41,9 +42,10 @@ export default class Desire extends Component {
</ScrollView>
<ActionButtonFooter
symptom='desire'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.desire}
saveAction={() => {
saveSymptom('desire', this.cycleDay, { value: this.state.currentValue })
saveSymptom('desire', this.props.date, { value: this.state.currentValue })
}}
saveDisabled={typeof this.state.currentValue != 'number'}
navigate={this.props.navigate}
+7 -9
View File
@@ -16,13 +16,10 @@ import SymptomSection from './symptom-section'
export default class Mucus extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.mucus = cycleDay && cycleDay.mucus
this.makeActionButtons = props.makeActionButtons
this.state = {
exclude: this.cycleDay.mucus ? this.cycleDay.mucus.exclude : false,
feeling: this.cycleDay.mucus ? this.cycleDay.mucus.feeling : null,
texture: this.cycleDay.mucus ? this.cycleDay.mucus.texture : null
}
this.state = this.mucus ? this.mucus : {}
}
render() {
@@ -75,15 +72,16 @@ export default class Mucus extends Component {
</ScrollView>
<ActionButtonFooter
symptom='mucus'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.mucus}
saveAction={() => {
const feeling = this.state.feeling
const texture = this.state.texture
saveSymptom('mucus', this.cycleDay, {
saveSymptom('mucus', this.props.date, {
feeling,
texture,
value: computeSensiplanValue(feeling, texture),
exclude: this.state.exclude
exclude: Boolean(this.state.exclude)
})
}}
saveDisabled={typeof this.state.feeling != 'number' || typeof this.state.texture != 'number'}
+6 -5
View File
@@ -14,12 +14,12 @@ import { noteExplainer } from '../labels'
export default class Note extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const note = this.cycleDay.note
const cycleDay = props.cycleDay
this.note = cycleDay && cycleDay.note
this.makeActionButtons = props.makeActionButtons
this.state = {
currentValue: note && note.value || ''
currentValue: this.note && this.note.value || ''
}
}
@@ -43,9 +43,10 @@ export default class Note extends Component {
</ScrollView>
<ActionButtonFooter
symptom='note'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.note}
saveAction={() => {
saveSymptom('note', this.cycleDay, {
saveSymptom('note', this.props.date, {
value: this.state.currentValue
})
}}
+12 -37
View File
@@ -11,43 +11,17 @@ import SelectBoxGroup from '../select-box-group'
import SymptomSection from './symptom-section'
import styles from '../../../styles'
const categories = labels.categories
const boxes = [{
label: categories.cramps,
stateKey: 'cramps'
}, {
label: categories.ovulationPain,
stateKey: 'ovulationPain'
}, {
label: categories.headache,
stateKey: 'headache'
}, {
label: categories.backache,
stateKey: 'backache'
}, {
label: categories.nausea,
stateKey: 'nausea'
}, {
label: categories.tenderBreasts,
stateKey: 'tenderBreasts'
}, {
label: categories.migraine,
stateKey: 'migraine'
}, {
label: categories.other,
stateKey: 'other'
}]
export default class Pain extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.state = {}
if (this.cycleDay.pain !== null ) {
Object.assign(this.state, this.cycleDay.pain)
if (this.cycleDay.pain && this.cycleDay.pain.note) {
this.state.other = true
}
const cycleDay = props.cycleDay
if (cycleDay && cycleDay.pain) {
this.state = Object.assign({}, cycleDay.pain)
} else {
this.state = {}
}
if (this.state.note) {
this.state.other = true
}
}
@@ -67,7 +41,7 @@ export default class Pain extends Component {
explainer={labels.explainer}
>
<SelectBoxGroup
data={boxes}
labels={labels.categories}
onSelect={this.toggleState}
optionsState={this.state}
/>
@@ -86,13 +60,14 @@ export default class Pain extends Component {
</ScrollView>
<ActionButtonFooter
symptom='pain'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.state}
saveAction={() => {
const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) {
copyOfState.note = null
}
saveSymptom('pain', this.cycleDay, copyOfState)
saveSymptom('pain', this.props.date, copyOfState)
}}
saveDisabled={Object.values(this.state).every(value => !value)}
navigate={this.props.navigate}
+16 -53
View File
@@ -6,61 +6,23 @@ import {
} from 'react-native'
import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import { sex as labels } from '../labels'
import { sex as sexLabels, contraceptives as cLabels } from '../labels'
import ActionButtonFooter from './action-button-footer'
import SelectBoxGroup from '../select-box-group'
import SymptomSection from './symptom-section'
const sexBoxes = [{
label: labels.solo,
stateKey: 'solo'
}, {
label: labels.partner,
stateKey: 'partner'
}]
const contraceptiveBoxes = [{
label: labels.condom,
stateKey: 'condom'
}, {
label: labels.pill,
stateKey: 'pill'
}, {
label: labels.iud,
stateKey: 'iud'
}, {
label: labels.patch,
stateKey: 'patch'
}, {
label: labels.ring,
stateKey: 'ring'
}, {
label: labels.implant,
stateKey: 'implant'
}, {
label: labels.diaphragm,
stateKey: 'diaphragm'
}, {
label: labels.none,
stateKey: 'none'
}, {
label: labels.other,
stateKey: 'other'
}]
export default class Sex extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.state = {}
if (this.cycleDay.sex !== null) {
Object.assign(this.state, this.cycleDay.sex)
// We make sure other is always true when there is a note,
// e.g. when import is messed up.
if (this.cycleDay.sex && this.cycleDay.sex.note) {
this.state.other = true
}
const cycleDay = props.cycleDay
if (cycleDay && cycleDay.sex) {
this.state = Object.assign({}, cycleDay.sex)
} else {
this.state = {}
}
// We make sure other is always true when there is a note,
// e.g. when import is messed up.
if (this.state.note) this.state.other = true
}
toggleState = (key) => {
@@ -77,20 +39,20 @@ export default class Sex extends Component {
<ScrollView style={styles.page}>
<SymptomSection
header="Activity"
explainer={labels.activityExplainer}
explainer={sexLabels.explainer}
>
<SelectBoxGroup
data={sexBoxes}
labels={sexLabels.categories}
onSelect={this.toggleState}
optionsState={this.state}
/>
</SymptomSection>
<SymptomSection
header="Contraceptives"
explainer={labels.contraceptiveExplainer}
explainer={cLabels.explainer}
>
<SelectBoxGroup
data={contraceptiveBoxes}
labels={cLabels.categories}
onSelect={this.toggleState}
optionsState={this.state}
/>
@@ -110,13 +72,14 @@ export default class Sex extends Component {
</ScrollView>
<ActionButtonFooter
symptom='sex'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.state}
saveAction={() => {
const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) {
copyOfState.note = null
}
saveSymptom('sex', this.cycleDay, copyOfState)
saveSymptom('sex', this.props.date, copyOfState)
}}
saveDisabled={Object.values(this.state).every(value => !value)}
navigate={this.props.navigate}
+8 -6
View File
@@ -25,10 +25,11 @@ const minutes = ChronoUnit.MINUTES
export default class Temp extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
const cycleDay = props.cycleDay
this.temperature = cycleDay && cycleDay.temperature
this.makeActionButtons = props.makeActionButtons
const temp = this.cycleDay.temperature
const temp = this.temperature
this.state = {
exclude: temp ? temp.exclude : false,
@@ -44,7 +45,7 @@ export default class Temp extends Component {
this.state.temperature = `${this.state.temperature}.0`
}
} else {
const prevTemp = getPreviousTemperature(this.cycleDay)
const prevTemp = getPreviousTemperature(this.props.date)
if (prevTemp) {
this.state.temperature = prevTemp.toString()
this.state.isSuggestion = true
@@ -59,8 +60,8 @@ export default class Temp extends Component {
time: this.state.time,
note: this.state.note
}
saveSymptom('temperature', this.cycleDay, dataToSave)
this.props.navigate('CycleDay', {cycleDay: this.cycleDay})
saveSymptom('temperature', this.props.date, dataToSave)
this.props.navigate('CycleDay', {date: this.props.date})
}
checkRangeAndSave = () => {
@@ -164,7 +165,8 @@ export default class Temp extends Component {
</ScrollView>
<ActionButtonFooter
symptom='temperature'
cycleDay={this.cycleDay}
date={this.props.date}
currentSymptomValue={this.temperature}
saveAction={() => this.checkRangeAndSave()}
saveDisabled={
this.state.temperature === '' ||
+2 -4
View File
@@ -8,7 +8,7 @@ import { home as labels, bleedingPrediction as predictLabels, shared } from './l
import CycleDayIcon from '../assets/home-circle'
import Drop from '../assets/home-drop'
import cycleModule from '../lib/cycle'
import { getOrCreateCycleDay, getCycleDaysSortedByDate } from '../db'
import { getCycleDaysSortedByDate } from '../db'
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
import styles from '../styles'
import AppText, { AppTextLight } from './app-text'
@@ -51,10 +51,8 @@ export default class Home extends Component {
}
passTodayTo(componentName) {
const todayDateString = LocalDate.now().toString()
const cycleDay = getOrCreateCycleDay(todayDateString)
const navigate = this.props.navigate
navigate(componentName, { cycleDay })
navigate(componentName, { date: LocalDate.now().toString() })
}
render() {
+16 -17
View File
@@ -68,8 +68,10 @@ export function getCycleDaysSortedByDate() {
export function getCycleStartsSortedByDate() {
return db.objects('CycleDay').filtered('isCycleStart = true').sorted('date', true)
}
export function saveSymptom(symptom, date, val) {
let cycleDay = getCycleDay(date)
if (!cycleDay) cycleDay = createCycleDay(date)
export function saveSymptom(symptom, cycleDay, val) {
db.write(() => {
if (bleedingValueDeleted(symptom, val)) {
cycleDay.bleeding = val
@@ -123,28 +125,25 @@ export function updateCycleStartsForAllCycleDays() {
})
}
export function getOrCreateCycleDay(localDate) {
let result = db.objectForPrimaryKey('CycleDay', localDate)
if (!result) {
db.write(() => {
result = db.create('CycleDay', {
date: localDate,
isCycleStart: false
})
export function createCycleDay(dateString) {
let result
db.write(() => {
result = db.create('CycleDay', {
date: dateString,
isCycleStart: false
})
}
})
return result
}
export function getCycleDay(localDate) {
return db.objectForPrimaryKey('CycleDay', localDate)
export function getCycleDay(dateString) {
return db.objectForPrimaryKey('CycleDay', dateString)
}
export function getPreviousTemperature(cycleDay) {
cycleDay.wrappedDate = LocalDate.parse(cycleDay.date)
const winner = getTemperatureDaysSortedByDate().find(day => {
const wrappedDate = LocalDate.parse(day.date)
return wrappedDate.isBefore(cycleDay.wrappedDate)
export function getPreviousTemperature(date) {
const targetDate = LocalDate.parse(date)
const winner = getTemperatureDaysSortedByDate().find(candidate => {
return LocalDate.parse(candidate.date).isBefore(targetDate)
})
if (!winner) return null
return winner.temperature.value
+2 -4
View File
@@ -3,7 +3,7 @@ import Notification from 'react-native-push-notification'
import { LocalDate } from 'js-joda'
import Moment from 'moment'
import { settings as labels } from '../components/labels'
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
import { getBleedingDaysSortedByDate } from '../db'
import cycleModule from './cycle'
import nothingChanged from '../db/db-unchanged'
@@ -11,9 +11,7 @@ export default function setupNotifications(navigate) {
Notification.configure({
onNotification: (notification) => {
if (notification.id === '1') {
const todayDateString = LocalDate.now().toString()
const cycleDay = getOrCreateCycleDay(todayDateString)
navigate('TemperatureEditView', { cycleDay })
navigate('TemperatureEditView', { date: LocalDate.now().toString() })
} else {
navigate('Home')
}