From 767a2c970934d99f61a10ea4ec3f50b58e0eb4a5 Mon Sep 17 00:00:00 2001 From: mashazyu Date: Mon, 18 Nov 2019 14:36:54 +0100 Subject: [PATCH] Introduces CycleDayLabel component --- components/chart/cycle-day-label.js | 39 +++++++++++++++++++++++++++++ components/chart/day-column.js | 38 ++++++---------------------- 2 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 components/chart/cycle-day-label.js diff --git a/components/chart/cycle-day-label.js b/components/chart/cycle-day-label.js new file mode 100644 index 0000000..38a0d2e --- /dev/null +++ b/components/chart/cycle-day-label.js @@ -0,0 +1,39 @@ +import React from 'react' +import PropTypes from 'prop-types' + +import { Text, View } from 'react-native' + +import moment from 'moment' +import { LocalDate } from 'js-joda' + +import styles from './styles' +import cycleModule from '../../lib/cycle' + +const CycleDayLabel = ({ height, date }) => { + const { label } = styles.column + const dayDate = LocalDate.parse(date) + const cycleDayNumber = cycleModule().getCycleDayNumber(date) + + const isFirstDayOfMonth = dayDate.dayOfMonth() === 1 + const dateFormatting = isFirstDayOfMonth ? 'MMM' : 'Do' + const shortDate = moment(date, "YYYY-MM-DD").format(dateFormatting) + const boldDateLabel = isFirstDayOfMonth ? {fontWeight: 'bold'} : {} + + return ( + + + {cycleDayNumber ? cycleDayNumber : ' '} + + + {shortDate} + + + ) +} + +CycleDayLabel.propTypes = { + height: PropTypes.number, + date: PropTypes.string, +} + +export default CycleDayLabel diff --git a/components/chart/day-column.js b/components/chart/day-column.js index 00fb6cf..0304ea6 100644 --- a/components/chart/day-column.js +++ b/components/chart/day-column.js @@ -1,26 +1,20 @@ import React, { Component } from 'react' -import { - Text, View, TouchableOpacity -} from 'react-native' +import { TouchableOpacity } from 'react-native' import { Surface } from 'react-native/Libraries/ART/ReactNativeART' import { connect } from 'react-redux' import { setDate } from '../../slices/date' import { LocalDate } from 'js-joda' -import moment from 'moment' -import styles from './styles' import config from '../../config' -import cycleModule from '../../lib/cycle' import { getCycleDay } from '../../db' import SymptomCell from './symptom-cell' import TemperatureColumn from './temperature-column' +import CycleDayLabel from './cycle-day-label' import { normalizeToScale } from '../helpers/chart' -const label = styles.column.label - class DayColumn extends Component { constructor(props) { super() @@ -143,24 +137,6 @@ class DayColumn extends Component { columnHeight, xAxisHeight } = this.props - const cycleDayNumber = cycleModule().getCycleDayNumber(dateString) - const dayDate = LocalDate.parse(dateString) - const shortDate = dayDate.dayOfMonth() === 1 ? - moment(dateString, "YYYY-MM-DD").format('MMM') - : - moment(dateString, "YYYY-MM-DD").format('Do') - const boldDateLabel = dayDate.dayOfMonth() === 1 ? {fontWeight: 'bold'} : {} - - const cycleDayLabel = ( - - {cycleDayNumber ? cycleDayNumber : ' '} - ) - const dateLabel = ( - - {shortDate} - - ) - return ( this.onDaySelect(dateString)} @@ -191,10 +167,11 @@ class DayColumn extends Component { /> - - {cycleDayLabel} - {dateLabel} - + + ) } @@ -211,7 +188,6 @@ export default connect( mapDispatchToProps, )(DayColumn) - function getInfoForNeighborColumns(dateString, columnHeight) { const ret = { rightY: null,