Newer
Older
import { TouchableOpacity } from 'react-native'
import { connect } from 'react-redux'
import { setDate } from '../../slices/date'
import { getCycleDay } from '../../db'
import TemperatureColumn from './temperature-column'
import CycleDayLabel from './cycle-day-label'
import {
symptomColorMethods,
getTemperatureProps,
isSymptomDataComplete
} from '../helpers/chart'
class DayColumn extends Component {
constructor(props) {
const { dateString, chartSymptoms, columnHeight } = props
const cycleDayData = getCycleDay(dateString)
this.data = {}
if (cycleDayData) {
this.data = chartSymptoms.reduce((symptomDataToDisplay, symptom, ) => {
const symptomData = cycleDayData[symptom]
if (symptomData && symptom === 'temperature') {
symptomDataToDisplay[symptom] =
getTemperatureProps(symptomData, columnHeight, dateString)
} else {
if (symptomData && ! symptomData.exclude) {
// if symptomColorMethods entry doesn't exist for given symptom,
// use 'default'
const getSymptomColorIndex =
symptomColorMethods[symptom] || symptomColorMethods['default']
symptomDataToDisplay[symptom] = getSymptomColorIndex(symptomData)
}
}
return symptomDataToDisplay
}, this.data)
}
this.fhmAndLtl = props.getFhmAndLtlInfo(
props.dateString,
this.data.temperature ? this.data.temperature.value : null,
props.columnHeight
)
onDaySelect = (date) => {
this.props.setDate(date)
this.props.navigate('CycleDay')
}
const { dateString,
symptomRowSymptoms,
columnHeight,
xAxisHeight } = this.props
onPress={() => this.onDaySelect(dateString)}
{ symptomRowSymptoms.map(symptom => {
const hasSymptomData = this.data.hasOwnProperty(symptom)
return (
<SymptomCell
key={symptom}
symptom={symptom}
symptomValue={hasSymptomData && this.data[symptom]}
isSymptomDataComplete={
hasSymptomData && isSymptomDataComplete(symptom, dateString)
}
height={this.props.symptomHeight}
/>)
}
)}
<TemperatureColumn
horizontalLinePosition={this.fhmAndLtl.drawLtlAt}
isVerticalLine={this.fhmAndLtl.drawFhmLine}
data={this.data && this.data.temperature}
columnHeight={columnHeight}
/>
<CycleDayLabel
height={xAxisHeight}
date={dateString}
/>