Newer
Older
import React, { Component } from 'react'
import {
View,
Button,
Text
} from 'react-native'
import styles from '../../styles'
mucusFeeling as feelingLabels,
mucusTexture as textureLabels,
mucusNFP as computeSensiplanMucusLabels,
cervixOpening as openingLabels,
cervixFirmness as firmnessLabels,
cervixPosition as positionLabels
import cycleDayModule from '../../lib/cycle'
const getCycleDayNumber = cycleDayModule().getCycleDayNumber
export default class DayView extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.showView = props.showView
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() {
bleedingDaysSortedByDate.removeListener(this.setStateWithCurrentCycleDayNumber)
}
render() {
return (
<View style={styles.symptomEditView}>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Bleeding</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('bleedingEditView')}
</Button>
</View>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Temperature</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('temperatureEditView')}
title={getLabel('temperature', cycleDay.temperature)}>
<View style={ styles.symptomViewRowInline }>
<Text style={styles.symptomDayView}>Mucus</Text>
<Button
onPress={() => this.showView('mucusEditView')}
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Cervix</Text>
<Button
onPress={() => this.showView('cervixEditView')}
title={getLabel('cervix', cycleDay.cervix)}>
</Button>
</View>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Note</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('noteEditView')}
title={getLabel('note', cycleDay.note)}
>
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function getLabel(symptomName, symptom) {
const labels = {
bleeding: bleeding => {
if (typeof bleeding.value === 'number') {
let bleedingLabel = `${bleedingLabels[bleeding.value]}`
if (bleeding.exclude) bleedingLabel = "( " + bleedingLabel + " )"
return bleedingLabel
}
},
temperature: temperature => {
if (typeof temperature.value === 'number') {
let temperatureLabel = `${temperature.value} °C - ${temperature.time}`
if (temperature.exclude) {
temperatureLabel = "( " + temperatureLabel + " )"
}
return temperatureLabel
}
},
mucus: mucus => {
if (typeof mucus.feeling === 'number' && typeof mucus.texture === 'number') {
let mucusLabel = `${feelingLabels[mucus.feeling]} + ${textureLabels[mucus.texture]} ( ${computeSensiplanMucusLabels[mucus.computedNfp]} )`
if (mucus.exclude) mucusLabel = "( " + mucusLabel + " )"
return mucusLabel
}
},
cervix: cervix => {
if (cervix.opening > -1 && cervix.firmness > -1) {
let cervixLabel = `${openingLabels[cervix.opening]} + ${firmnessLabels[cervix.firmness]}`
if (cervix.position > -1) cervixLabel += `+ ${positionLabels[cervix.position]}`
if (cervix.exclude) cervixLabel = "( " + cervixLabel + " )"
return cervixLabel
}
},
note: note => {
return note.value.slice(0, 12) + '...'
}
}
if (!symptom) return 'edit'
return labels[symptomName](symptom) || 'edit'
}