Newer
Older
import React, { Component } from 'react'
import {
import { getOrCreateCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import Icon from 'react-native-vector-icons/FontAwesome'
import styles, { iconStyles } from '../../styles'
mucusFeeling as feelingLabels,
mucusTexture as textureLabels,
mucusNFP as computeSensiplanMucusLabels,
cervixOpening as openingLabels,
cervixFirmness as firmnessLabels,
cervixPosition as positionLabels,
intensity as intensityLabels
export default class CycleDayOverView extends Component {
constructor(props) {
super(props)
this.state = {
cycleDay: props.cycleDay
const localDate = LocalDate.parse(this.state.cycleDay.date)
const targetDate = target === 'before' ?
localDate.minusDays(1).toString() :
localDate.plusDays(1).toString()
this.setState({ cycleDay: getOrCreateCycleDay(targetDate) })
this.props.navigate(symptom, {
cycleDay: this.state.cycleDay,
const cycleDay = this.state.cycleDay
const getCycleDayNumber = cycleModule().getCycleDayNumber
const cycleDayNumber = getCycleDayNumber(cycleDay.date)
tina
committed
const dateInFuture = LocalDate.now().isBefore(LocalDate.parse(this.state.cycleDay.date))
isCycleDayOverView={true}
cycleDayNumber={cycleDayNumber}
date={cycleDay.date}
<ScrollView>
<View style={styles.symptomBoxesView}>
<SymptomBox
title='Bleeding'
onPress={() => this.navigate('BleedingEditView')}
data={getLabel('bleeding', cycleDay.bleeding)}
tina
committed
disabled={dateInFuture}
/>
<SymptomBox
title='Temperature'
onPress={() => this.navigate('TemperatureEditView')}
data={getLabel('temperature', cycleDay.temperature)}
tina
committed
disabled={dateInFuture}
/>
<SymptomBox
title='Mucus'
onPress={() => this.navigate('MucusEditView')}
data={getLabel('mucus', cycleDay.mucus)}
tina
committed
disabled={dateInFuture}
/>
<SymptomBox
title='Cervix'
onPress={() => this.navigate('CervixEditView')}
data={getLabel('cervix', cycleDay.cervix)}
tina
committed
disabled={dateInFuture}
/>
<SymptomBox
title='Desire'
onPress={() => this.navigate('DesireEditView')}
data={getLabel('desire', cycleDay.desire)}
tina
committed
disabled={dateInFuture}
/>
<SymptomBox
title='Sex'
onPress={() => this.navigate('SexEditView')}
data={getLabel('sex', cycleDay.sex)}
tina
committed
disabled={dateInFuture}
/>
<SymptomBox
title='Note'
onPress={() => this.navigate('NoteEditView')}
data={getLabel('note', cycleDay.note)}
/>
{/* this is just to make the last row adhere to the grid
<FillerBoxes />
</View >
</ScrollView >
</View >
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 => {
const categories = ['feeling', 'texture', 'value']
if (categories.every(c => typeof mucus[c] === 'number')) {
let mucusLabel = [feelingLabels[mucus.feeling], textureLabels[mucus.texture]].join(', ')
mucusLabel += `\n${computeSensiplanMucusLabels[mucus.value]}`
if (mucus.exclude) mucusLabel = `(${mucusLabel})`
return mucusLabel
}
},
cervix: cervix => {
if (cervix.opening > -1 && cervix.firmness > -1) {
cervixLabel.push(
openingLabels[cervix.opening],
firmnessLabels[cervix.firmness]
)
cervixLabel.push(positionLabels[cervix.position])
cervixLabel = cervixLabel.join(', ')
if (cervix.exclude) cervixLabel = `(${cervixLabel})`
return cervixLabel
}
},
note: note => {
},
desire: desire => {
if (typeof desire.value === 'number') {
const desireLabel = `${intensityLabels[desire.value]}`
}
if (sex.condom || sex.pill || sex.iud ||
sex.patch || sex.ring || sex.implant || sex.other) {
if (label.length < 45) return label
return label.slice(0, 42) + '...'
tina
committed
class SymptomBox extends Component {
render() {
const d = this.props.data
const boxActive = d ? styles.symptomBoxActive : {}
const iconActive = d ? iconStyles.symptomBoxActive : {}
tina
committed
const textActive = d ? styles.symptomTextActive : {}
const disabledStyle = this.props.disabled ? styles.symptomInFuture : {}
tina
committed
const symptomBoxStyle = Object.assign({}, styles.symptomBox, boxActive, disabledStyle)
const iconStyle = Object.assign({}, iconStyles.symptomBox, iconActive, disabledStyle)
const symptomDataBoxStyle = Object.assign({}, styles.symptomDataBox, disabledStyle)
const textStyle = Object.assign({}, textActive, disabledStyle)
tina
committed
<TouchableOpacity onPress={this.props.onPress} disabled={this.props.disabled}>
<View style={symptomBoxStyle}>
<Icon
name='thermometer'
{...iconStyle}
<Text style={textStyle}>{this.props.title}</Text>
tina
committed
<View style={symptomDataBoxStyle}>
<Text style={styles.symptomDataText}>{this.props.data}</Text>
</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