Skip to content
Snippets Groups Projects
Commit 767a2c97 authored by mashazyu's avatar mashazyu
Browse files

Introduces CycleDayLabel component

parent fe1ec38b
Branches
Tags
No related merge requests found
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 (
<View style={{ height }}>
<Text style={label.number}>
{cycleDayNumber ? cycleDayNumber : ' '}
</Text>
<Text style={[label.date, boldDateLabel]}>
{shortDate}
</Text>
</View>
)
}
CycleDayLabel.propTypes = {
height: PropTypes.number,
date: PropTypes.string,
}
export default CycleDayLabel
import React, { Component } from 'react' import React, { Component } from 'react'
import { import { TouchableOpacity } from 'react-native'
Text, View, TouchableOpacity
} from 'react-native'
import { Surface } from 'react-native/Libraries/ART/ReactNativeART' import { Surface } from 'react-native/Libraries/ART/ReactNativeART'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { setDate } from '../../slices/date' import { setDate } from '../../slices/date'
import { LocalDate } from 'js-joda' import { LocalDate } from 'js-joda'
import moment from 'moment'
import styles from './styles'
import config from '../../config' import config from '../../config'
import cycleModule from '../../lib/cycle'
import { getCycleDay } from '../../db' import { getCycleDay } from '../../db'
import SymptomCell from './symptom-cell' import SymptomCell from './symptom-cell'
import TemperatureColumn from './temperature-column' import TemperatureColumn from './temperature-column'
import CycleDayLabel from './cycle-day-label'
import { normalizeToScale } from '../helpers/chart' import { normalizeToScale } from '../helpers/chart'
const label = styles.column.label
class DayColumn extends Component { class DayColumn extends Component {
constructor(props) { constructor(props) {
super() super()
...@@ -143,24 +137,6 @@ class DayColumn extends Component { ...@@ -143,24 +137,6 @@ class DayColumn extends Component {
columnHeight, columnHeight,
xAxisHeight } = this.props 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 = (
<Text style = {label.number}>
{cycleDayNumber ? cycleDayNumber : ' '}
</Text>)
const dateLabel = (
<Text style = {[label.date, boldDateLabel]}>
{shortDate}
</Text>
)
return ( return (
<TouchableOpacity <TouchableOpacity
onPress={() => this.onDaySelect(dateString)} onPress={() => this.onDaySelect(dateString)}
...@@ -191,10 +167,11 @@ class DayColumn extends Component { ...@@ -191,10 +167,11 @@ class DayColumn extends Component {
/> />
</Surface> </Surface>
<View style={{height: xAxisHeight}}> <CycleDayLabel
{cycleDayLabel} height={xAxisHeight}
{dateLabel} date={dateString}
</View> />
</TouchableOpacity> </TouchableOpacity>
) )
} }
...@@ -211,7 +188,6 @@ export default connect( ...@@ -211,7 +188,6 @@ export default connect(
mapDispatchToProps, mapDispatchToProps,
)(DayColumn) )(DayColumn)
function getInfoForNeighborColumns(dateString, columnHeight) { function getInfoForNeighborColumns(dateString, columnHeight) {
const ret = { const ret = {
rightY: null, rightY: null,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment