import React, { Component } from 'react'
import Svg,{
G,
Rect,
Text,
Circle,
Line,
Path
} from 'react-native-svg'
import styles from './styles'
import config from './config'
import { getOrCreateCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import setUpFertilityStatusFunc from './nfp-lines'
import { horizontalGrid } from './y-axis'
const getCycleDayNumber = cycleModule().getCycleDayNumber
export default class DayColumn extends Component {
makeDayColumn(data, index) {
const {
dateString,
y,
temperature,
temperatureExclude,
bleeding,
mucus
} = data
const cycleDayNumber = getCycleDayNumber(dateString)
const label = styles.column.label
const dateLabel = dateString.split('-').slice(1).join('-')
const getFhmAndLtlInfo = setUpFertilityStatusFunc()
const nfpLineInfo = getFhmAndLtlInfo(dateString, cycleDay)
return (
this.passDateToDayView(dateString)}>
{horizontalGrid}
{nfpLineInfo.drawFhmLine ?
: null}
{cycleDayNumber}
{dateLabel}
{cycleDay && cycleDay.bleeding ?
: null}
{nfpLineInfo.drawLtlAt ?
: null}
{y ?
this.drawDotAndLines(y, cycleDay.temperature.exclude, index)
: null
}
{cycleDay && cycleDay.mucus ?
: null}
{y ?
this.drawDotAndLines(y, cycleDay.temperature.exclude)
: null}
)
}
drawDotAndLines(currY, exclude) {
let lineToRight
let lineToLeft
function makeLine(otherColY, x, excludeLine) {
const middleY = ((otherColY - currY) / 2) + currY
const target = [x, middleY]
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
return
}
const thereIsADotToTheRight = this.props.rightNeighbor && this.props.rightNeighbor.y
const thereIsADotToTheLeft = this.props.leftNeighbor && this.props.leftNeighbor.y
if (thereIsADotToTheRight) {
const neighbor = this.props.rightNeighbor
const excludedLine = neighbor.cycleDay.temperature.exclude || exclude
lineToRight = makeLine(neighbor.y, config.columnWidth, excludedLine)
}
if (thereIsADotToTheLeft) {
const neighbor = this.props.leftNeighbor
const excludedLine = neighbor.cycleDay.temperature.exclude || exclude
lineToLeft = makeLine(neighbor.y, 0, excludedLine)
}
const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots
return (
{lineToRight}
{lineToLeft}
)
}
passDateToDayView(dateString) {
const cycleDay = getOrCreateCycleDay(dateString)
this.props.navigate('cycleDay', { cycleDay })
}
shouldComponentUpdate() {
// for now, until we've solved the mysterious re-rendering
return false
}
render() {
console.log(this.props.index)
return (
)
}
}