diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/group-heading/index.js | 59 | ||||
| -rw-r--r-- | src/components/group-heading/styles.css | 3 | ||||
| -rw-r--r-- | src/components/repository-grid/grid-item/index.js | 2 | ||||
| -rw-r--r-- | src/containers/feed/index.js | 6 | ||||
| -rw-r--r-- | src/redux/github/actions.js | 4 |
5 files changed, 65 insertions, 9 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; diff --git a/src/components/group-heading/styles.css b/src/components/group-heading/styles.css new file mode 100644 index 0000000..3be9d76 --- /dev/null +++ b/src/components/group-heading/styles.css @@ -0,0 +1,3 @@ +.group-heading h4:first-letter { + text-transform: uppercase; +} diff --git a/src/components/repository-grid/grid-item/index.js b/src/components/repository-grid/grid-item/index.js index 18583c1..b77ebac 100644 --- a/src/components/repository-grid/grid-item/index.js +++ b/src/components/repository-grid/grid-item/index.js @@ -30,7 +30,7 @@ class GridItem extends React.Component { </a> </h5> <p className="repo-meta text-muted small"> - Built by · <a target="_blank" href={ this.props.repository.owner.html_url }>{ this.props.repository.owner.login }</a> · { moment(this.props.repository.created_at).format('MMMM D YYYY') } + Built by · <a target="_blank" href={ this.props.repository.owner.html_url }>{ this.props.repository.owner.login }</a> · { moment(this.props.repository.created_at).format('MMMM D, YYYY') } </p> </div> <div className="repo-body"> diff --git a/src/containers/feed/index.js b/src/containers/feed/index.js index 682ae5d..6121ec5 100644 --- a/src/containers/feed/index.js +++ b/src/containers/feed/index.js @@ -85,7 +85,11 @@ class FeedContainer extends React.Component { { this.props.github.repositories && this.props.github.repositories[0] && - <GroupHeading/> + <GroupHeading + start={ this.props.github.repositories[0].start } + end={ this.props.github.repositories[0].end } + dateJump={ this.props.preference.dateJump } + /> } <div className="group-filters"> { diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js index fe054a0..c61fd50 100644 --- a/src/redux/github/actions.js +++ b/src/redux/github/actions.js @@ -40,8 +40,8 @@ export const fetchTrending = function (filters) { dispatch({ type: FETCH_TRENDING_SUCCESS, payload: { - start: filters.dateRange.start, - end: filters.dateRange.end, + start: filters.dateRange.start.format(), + end: filters.dateRange.end.format(), data: response.data } }); |
