Skip to content
Snippets Groups Projects
day-column.js 5.02 KiB
Newer Older
import React, { Component } from 'react'
  Text, View, TouchableOpacity
} from 'react-native'
import Icon from 'react-native-vector-icons/Entypo'
import styles from './styles'
Julia Friesel's avatar
Julia Friesel committed
import config from '../../config'
import { getOrCreateCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import DotAndLine from './dot-and-line'

const getCycleDayNumber = cycleModule().getCycleDayNumber
const label = styles.column.label

export default class DayColumn extends Component {
  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,
tina's avatar
tina committed
      symptoms,
Julia Friesel's avatar
Julia Friesel committed
      drawFhmLine,
      drawLtlAt,
      rightY,
      rightTemperatureExclude,
      leftY,
      leftTemperatureExclude,
      chartHeight
    const columnHeight = chartHeight * config.columnHeightPercentage
    const xAxisHeight = chartHeight * config.xAxisHeightPercentage
    const symptomHeight = chartHeight * config.symptomRowHeightPercentage
Julia Friesel's avatar
Julia Friesel committed

    const columnElements = []
Julia Friesel's avatar
Julia Friesel committed
    if(drawLtlAt) {
Julia Friesel's avatar
Julia Friesel committed
      const ltlLine = (<View
        position = 'absolute'
        width={'100%'}
Julia Friesel's avatar
Julia Friesel committed
        top={drawLtlAt}
Julia Friesel's avatar
Julia Friesel committed
        {...styles.nfpLine}
Julia Friesel's avatar
Julia Friesel committed
      />)
      columnElements.push(ltlLine)
    }
      columnElements.push(
        <DotAndLine
          y={y}
          exclude={temperatureExclude}
Julia Friesel's avatar
Julia Friesel committed
          rightY={rightY}
          rightTemperatureExclude={rightTemperatureExclude}
          leftY={leftY}
          leftTemperatureExclude={leftTemperatureExclude}
          key='dotandline'
    const cycleDayNumber = getCycleDayNumber(dateString)
    const shortDate = dateString.split('-').slice(1).join('-')
    const cycleDayLabel = (
      <Text style = {label.number}>
        {cycleDayNumber ? cycleDayNumber : ' '}
      </Text>)
    const dateLabel = (
      <Text style = {label.date}>
        {shortDate}
      </Text>
    )
    // we merge the colors here instead of from the stylesheet because of a RN
    // bug that doesn't apply borderLeftColor otherwise
      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)
        },
tina's avatar
tina committed
        <View height={symptomHeight}>
          <View style={styles.symptomRow}>
            {typeof symptoms.bleeding === 'number' &&
              <Icon
                name='drop'
                size={12}
                color={styles.bleedingIconShades[symptoms.bleeding]}
                key='bleeding'
              />
            }
          </View>
          <View style={styles.symptomRow}>
            {typeof symptoms.mucus === 'number' &&
              <View
                {...styles.mucusIcon}
                backgroundColor={styles.mucusIconShades[symptoms.mucus]}
                key='mucus'
              />
            }
          </View>
          <View style={styles.symptomRow}>
            {typeof symptoms.cervix === 'number' &&
              <View
                {...styles.mucusIcon}
                // cervix is sum of openess and firmness - fertile only when closed and hard (=0)
                backgroundColor={symptoms.cervix > 0 ? 'blue' : 'green'}
                key='cervix'
              />
            }
          </View>
          <View style={styles.symptomRow}>
            {typeof symptoms.sex === 'number' &&
              <View
                {...styles.mucusIcon}
                backgroundColor='orange'
tina's avatar
tina committed
                key='sex'
              />
            }
          </View>
          <View style={styles.symptomRow}>
            {typeof symptoms.desire === 'number' &&
              <View
                {...styles.mucusIcon}
                backgroundColor='red'
                key='desire'
              />
            }
          </View>
          <View style={styles.symptomRow}>
            {symptoms.pain &&
              <View
                {...styles.mucusIcon}
                backgroundColor='blue'
                key='pain'
              />
            }
          </View>
          <View style={styles.symptomRow}>
            {symptoms.note &&
              <View
                {...styles.mucusIcon}
                backgroundColor='green'
                key='note'
              />
            }
          </View>
        </View>
        <View style={{height: xAxisHeight}}>
          {cycleDayLabel}
          {dateLabel}
        </View>
      </View>
    )
emelko's avatar
emelko committed
}