Introduces CycleDayLabel component

This commit is contained in:
mashazyu
2019-11-18 14:36:54 +01:00
parent fe1ec38b68
commit 767a2c9709
2 changed files with 46 additions and 31 deletions
+39
View File
@@ -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 (
<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
+7 -31
View File
@@ -1,26 +1,20 @@
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 {
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 {
/> />
</Surface> </Surface>
<View style={{height: xAxisHeight}}> <CycleDayLabel
{cycleDayLabel} height={xAxisHeight}
{dateLabel} date={dateString}
</View> />
</TouchableOpacity> </TouchableOpacity>
) )
} }
@@ -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,