Chore/make function components 7
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { TouchableOpacity } from 'react-native'
|
import { TouchableOpacity } from 'react-native'
|
||||||
|
|
||||||
@@ -14,29 +14,23 @@ import {
|
|||||||
isSymptomDataComplete,
|
isSymptomDataComplete,
|
||||||
} from '../helpers/chart'
|
} from '../helpers/chart'
|
||||||
|
|
||||||
class DayColumn extends Component {
|
const DayColumn = ({
|
||||||
static propTypes = {
|
dateString,
|
||||||
dateString: PropTypes.string.isRequired,
|
chartSymptoms,
|
||||||
chartSymptoms: PropTypes.array,
|
columnHeight,
|
||||||
columnHeight: PropTypes.number.isRequired,
|
getFhmAndLtlInfo,
|
||||||
getFhmAndLtlInfo: PropTypes.func.isRequired,
|
setDate,
|
||||||
navigate: PropTypes.func.isRequired,
|
navigate,
|
||||||
setDate: PropTypes.func.isRequired,
|
shouldShowTemperatureColumn,
|
||||||
shouldShowTemperatureColumn: PropTypes.bool,
|
symptomHeight,
|
||||||
symptomHeight: PropTypes.number.isRequired,
|
symptomRowSymptoms,
|
||||||
symptomRowSymptoms: PropTypes.array,
|
xAxisHeight,
|
||||||
xAxisHeight: PropTypes.number,
|
}) => {
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super()
|
|
||||||
|
|
||||||
const { dateString, chartSymptoms, columnHeight } = props
|
|
||||||
const cycleDayData = getCycleDay(dateString)
|
const cycleDayData = getCycleDay(dateString)
|
||||||
this.data = {}
|
let data = {}
|
||||||
|
|
||||||
if (cycleDayData) {
|
if (cycleDayData) {
|
||||||
this.data = chartSymptoms.reduce((symptomDataToDisplay, symptom) => {
|
data = chartSymptoms.reduce((symptomDataToDisplay, symptom) => {
|
||||||
const symptomData = cycleDayData[symptom]
|
const symptomData = cycleDayData[symptom]
|
||||||
|
|
||||||
if (symptomData && symptom === 'temperature') {
|
if (symptomData && symptom === 'temperature') {
|
||||||
@@ -57,45 +51,27 @@ class DayColumn extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return symptomDataToDisplay
|
return symptomDataToDisplay
|
||||||
}, this.data)
|
}, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fhmAndLtl = props.getFhmAndLtlInfo(
|
const fhmAndLtl = getFhmAndLtlInfo(
|
||||||
props.dateString,
|
|
||||||
this.data.temperature ? this.data.temperature.value : null,
|
|
||||||
props.columnHeight
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onDaySelect = (date) => {
|
|
||||||
this.props.setDate(date)
|
|
||||||
this.props.navigate('CycleDay')
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldComponentUpdate() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
columnHeight,
|
|
||||||
dateString,
|
dateString,
|
||||||
shouldShowTemperatureColumn,
|
data.temperature ? data.temperature.value : null,
|
||||||
symptomHeight,
|
columnHeight
|
||||||
symptomRowSymptoms,
|
)
|
||||||
xAxisHeight,
|
|
||||||
} = this.props
|
const onDaySelect = (date) => {
|
||||||
|
setDate(date)
|
||||||
|
navigate('CycleDay')
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity onPress={() => onDaySelect(dateString)} activeOpacity={1}>
|
||||||
onPress={() => this.onDaySelect(dateString)}
|
|
||||||
activeOpacity={1}
|
|
||||||
>
|
|
||||||
{shouldShowTemperatureColumn && (
|
{shouldShowTemperatureColumn && (
|
||||||
<TemperatureColumn
|
<TemperatureColumn
|
||||||
horizontalLinePosition={this.fhmAndLtl.drawLtlAt}
|
horizontalLinePosition={fhmAndLtl.drawLtlAt}
|
||||||
isVerticalLine={this.fhmAndLtl.drawFhmLine}
|
isVerticalLine={fhmAndLtl.drawFhmLine}
|
||||||
data={this.data && this.data.temperature}
|
data={data && data.temperature}
|
||||||
columnHeight={columnHeight}
|
columnHeight={columnHeight}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -104,7 +80,7 @@ class DayColumn extends Component {
|
|||||||
|
|
||||||
{symptomRowSymptoms.map((symptom, i) => {
|
{symptomRowSymptoms.map((symptom, i) => {
|
||||||
const hasSymptomData = Object.prototype.hasOwnProperty.call(
|
const hasSymptomData = Object.prototype.hasOwnProperty.call(
|
||||||
this.data,
|
data,
|
||||||
symptom
|
symptom
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
@@ -112,7 +88,7 @@ class DayColumn extends Component {
|
|||||||
index={i}
|
index={i}
|
||||||
key={symptom}
|
key={symptom}
|
||||||
symptom={symptom}
|
symptom={symptom}
|
||||||
symptomValue={hasSymptomData && this.data[symptom]}
|
symptomValue={hasSymptomData && data[symptom]}
|
||||||
isSymptomDataComplete={
|
isSymptomDataComplete={
|
||||||
hasSymptomData && isSymptomDataComplete(symptom, dateString)
|
hasSymptomData && isSymptomDataComplete(symptom, dateString)
|
||||||
}
|
}
|
||||||
@@ -123,6 +99,18 @@ class DayColumn extends Component {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DayColumn.propTypes = {
|
||||||
|
dateString: PropTypes.string.isRequired,
|
||||||
|
chartSymptoms: PropTypes.array,
|
||||||
|
columnHeight: PropTypes.number.isRequired,
|
||||||
|
getFhmAndLtlInfo: PropTypes.func.isRequired,
|
||||||
|
navigate: PropTypes.func.isRequired,
|
||||||
|
setDate: PropTypes.func.isRequired,
|
||||||
|
shouldShowTemperatureColumn: PropTypes.bool,
|
||||||
|
symptomHeight: PropTypes.number.isRequired,
|
||||||
|
symptomRowSymptoms: PropTypes.array,
|
||||||
|
xAxisHeight: PropTypes.number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DayColumn
|
export default DayColumn
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Path, Shape } from '@react-native-community/art'
|
import { Path, Shape } from '@react-native-community/art'
|
||||||
|
|
||||||
@@ -11,29 +11,14 @@ import {
|
|||||||
CHART_STROKE_WIDTH,
|
CHART_STROKE_WIDTH,
|
||||||
} from '../../config'
|
} from '../../config'
|
||||||
|
|
||||||
export default class DotAndLine extends Component {
|
const DotAndLine = ({
|
||||||
static propTypes = {
|
|
||||||
exclude: PropTypes.bool,
|
|
||||||
leftY: PropTypes.number,
|
|
||||||
leftTemperatureExclude: PropTypes.bool,
|
|
||||||
rightY: PropTypes.number,
|
|
||||||
rightTemperatureExclude: PropTypes.bool,
|
|
||||||
y: PropTypes.number.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldComponentUpdate(newProps) {
|
|
||||||
return Object.keys(newProps).some((key) => newProps[key] != this.props[key])
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
exclude,
|
exclude,
|
||||||
leftTemperatureExclude,
|
leftTemperatureExclude,
|
||||||
leftY,
|
leftY,
|
||||||
rightTemperatureExclude,
|
rightTemperatureExclude,
|
||||||
rightY,
|
rightY,
|
||||||
y,
|
y,
|
||||||
} = this.props
|
}) => {
|
||||||
let excludeLeftLine, excludeRightLine, lineLeft, lineRight
|
let excludeLeftLine, excludeRightLine, lineLeft, lineRight
|
||||||
|
|
||||||
if (leftY) {
|
if (leftY) {
|
||||||
@@ -85,4 +70,14 @@ export default class DotAndLine extends Component {
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DotAndLine.propTypes = {
|
||||||
|
exclude: PropTypes.bool,
|
||||||
|
leftY: PropTypes.number,
|
||||||
|
leftTemperatureExclude: PropTypes.bool,
|
||||||
|
rightY: PropTypes.number,
|
||||||
|
rightTemperatureExclude: PropTypes.bool,
|
||||||
|
y: PropTypes.number.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default DotAndLine
|
||||||
|
|||||||
Reference in New Issue
Block a user