Newer
Older
import React, { Component } from 'react'
import {
import cycleModule from '../../lib/cycle'
import styles from '../../styles'
import * as labels from '../../i18n/en/cycle-day'
import DripIcon from '../../assets/drip-icons'
const bleedingLabels = labels.bleeding
const feelingLabels = labels.mucus.feeling.categories
const textureLabels = labels.mucus.texture.categories
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.categories
const contraceptiveLabels = labels.contraceptives.categories
export default class CycleDayOverView extends Component {
constructor(props) {
super(props)
this.state = {
date: this.props.date,
cycleDay: getCycleDay(this.props.date)
const localDate = LocalDate.parse(this.state.date)
const targetDate = target === 'before' ?
localDate.minusDays(1).toString() :
localDate.plusDays(1).toString()
this.setState({
date: targetDate,
cycleDay: getCycleDay(targetDate)
})
const cycleDay = this.state.cycleDay
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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(this.state.date)
.isBefore(LocalDate.parse(this.state.date))
isCycleDayOverView={true}
<ScrollView>
<View style={styles.symptomBoxesView}>
<SymptomBox
title='Bleeding'
onPress={() => this.navigate('BleedingEditView')}
tina
committed
disabled={dateInFuture}
<SymptomBox
title='Temperature'
onPress={() => this.navigate('TemperatureEditView')}
tina
committed
disabled={dateInFuture}
<SymptomBox
title='Mucus'
onPress={() => this.navigate('MucusEditView')}
tina
committed
disabled={dateInFuture}
>
</SymptomBox>
<SymptomBox
title='Cervix'
onPress={() => this.navigate('CervixEditView')}
tina
committed
disabled={dateInFuture}
<SymptomBox
title='Desire'
onPress={() => this.navigate('DesireEditView')}
tina
committed
disabled={dateInFuture}
<SymptomBox
title='Sex'
onPress={() => this.navigate('SexEditView')}
tina
committed
disabled={dateInFuture}
<SymptomBox
title='Pain'
onPress={() => this.navigate('PainEditView')}
disabled={dateInFuture}
<SymptomBox
title='Note'
onPress={() => this.navigate('NoteEditView')}
{/* this is just to make the last row adhere to the grid
<FillerBoxes />
</View >
</ScrollView >
</View >
tina
committed
class SymptomBox extends Component {
render() {
const d = this.props.data
const boxActive = d ? styles.symptomBoxActive : {}
tina
committed
const textActive = d ? styles.symptomTextActive : {}
const disabledStyle = this.props.disabled ? styles.symptomInFuture : {}
<TouchableOpacity
onPress={this.props.onPress}
disabled={this.props.disabled}
>
<View style={[styles.symptomBox, boxActive, disabledStyle]}>
<DripIcon name={this.props.iconName} size={50} color={d ? 'white' : 'black'}/>
<AppText style={styles.symptomDataText}>{this.props.data}</AppText>
</View>
</TouchableOpacity>
)
}
}
class FillerBoxes extends Component {
render() {
const n = Dimensions.get('window').width / styles.symptomBox.width
const fillerBoxes = []
for (let i = 0; i < Math.ceil(n); i++) {
fillerBoxes.push(
<View
height={0}
key={i.toString()}
/>
)
}
return fillerBoxes
function isNumber(val) {
return typeof val === 'number'
}