import React, { Component } from 'react' import { Text, View, TouchableOpacity } from 'react-native' import Icon from 'react-native-vector-icons/Entypo' import styles from './styles' import config from '../../config' import { getOrCreateCycleDay } from '../../db' import cycleModule from '../../lib/cycle' import DotAndLine from './dot-and-line' const label = styles.column.label export default class DayColumn extends Component { constructor() { super() this.getCycleDayNumber = cycleModule().getCycleDayNumber } passDateToDayView(dateString) { const cycleDay = getOrCreateCycleDay(dateString) this.props.navigate('CycleDay', { cycleDay }) } shouldComponentUpdate(newProps) { return Object.keys(newProps).some(key => newProps[key] != this.props[key]) } render() { const { dateString, y, temperatureExclude, symptoms, drawFhmLine, drawLtlAt, rightY, rightTemperatureExclude, leftY, leftTemperatureExclude, chartHeight } = this.props const columnHeight = chartHeight * config.columnHeightPercentage const xAxisHeight = chartHeight * config.xAxisHeightPercentage const symptomHeight = chartHeight * config.symptomRowHeightPercentage const columnElements = [] if(drawLtlAt) { const ltlLine = () columnElements.push(ltlLine) } if (y) { columnElements.push( ) } const cycleDayNumber = this.getCycleDayNumber(dateString) const shortDate = dateString.split('-').slice(1).join('-') const cycleDayLabel = ( {cycleDayNumber ? cycleDayNumber : ' '} ) const dateLabel = ( {shortDate} ) // we merge the colors here instead of from the stylesheet because of a RN // bug that doesn't apply borderLeftColor otherwise const potentialCustomStyle = { height: columnHeight, borderLeftColor: 'grey', } if (drawFhmLine) { potentialCustomStyle.borderLeftColor = styles.nfpLine.borderColor potentialCustomStyle.borderLeftWidth = 3 } const column = React.createElement( TouchableOpacity, { style: [styles.column.rect, potentialCustomStyle], key: this.props.index.toString(), onPress: () => { this.passDateToDayView(dateString) }, activeOpacity: 1 }, columnElements ) return ( {typeof symptoms.bleeding === 'number' && } {typeof symptoms.mucus === 'number' && } {typeof symptoms.cervix === 'number' && 0 ? 'blue' : 'green'} key='cervix' /> } {typeof symptoms.sex === 'number' && } {typeof symptoms.desire === 'number' && } {symptoms.pain && } {symptoms.note && } {column} {cycleDayLabel} {dateLabel} ) } }