diff options
Diffstat (limited to 'src/components/group-heading/index.js')
| -rw-r--r-- | src/components/group-heading/index.js | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/components/group-heading/index.js b/src/components/group-heading/index.js index af5f743..762d36d 100644 --- a/src/components/group-heading/index.js +++ b/src/components/group-heading/index.js @@ -1,9 +1,58 @@ import React from 'react'; +import moment from 'moment'; +import PropTypes from 'prop-types'; -const GroupHeading = (props) => ( - <div className="group-heading"> - <h4>Today <span className="small text-muted">July 12, 2019</span></h4> - </div> -); +import './styles.css'; + +class GroupHeading extends React.Component { + getTitle() { + const startMoment = moment(this.props.start); + const currentMoment = moment(); + const yesterdayMoment = moment().subtract(1, 'day'); + + // For "day" jumps show the day name + if (this.props.dateJump === 'day') { + if (startMoment.isSame(currentMoment, 'day')) { + return 'Today'; + } else if (startMoment.isSame(yesterdayMoment, 'day')) { + return 'Yesterday'; + } + + return startMoment.format('dddd'); + } + + return startMoment.fromNow(); + } + + getSubtitle() { + const startMoment = moment(this.props.start); + const endMoment = moment(this.props.end); + + if (startMoment.isSame(endMoment, 'day')) { + return startMoment.format('MMMM D, YYYY'); + } + + return startMoment.format('MMMM D, YYYY') + ' – ' + endMoment.format('MMMM D, YYYY'); + } + + render() { + return ( + <div className="group-heading"> + <h4> + <span className="text-capitalizes">{ this.getTitle() }</span> + <span className="small text-muted ml-2"> + { this.getSubtitle() } + </span> + </h4> + </div> + ); + } +} + +GroupHeading.propTypes = { + start: PropTypes.string, + end: PropTypes.string, + dateJump: PropTypes.oneOf(['week', 'month', 'year', 'day']) +}; export default GroupHeading; |
