2018-02-19 20:32:14 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import format from 'date-fns/format';
|
|
|
|
|
import { reverse, sortBy } from 'lodash';
|
|
|
|
|
import {
|
|
|
|
|
Table
|
|
|
|
|
} from 'react-bootstrap';
|
|
|
|
|
|
|
|
|
|
import { challengeIdToNameMapSelector } from '../../../entities';
|
2018-05-15 06:12:05 +01:00
|
|
|
import { userByNameSelector } from '../../../redux';
|
2018-02-19 20:32:14 +00:00
|
|
|
import { homeURL } from '../../../../utils/constantStrings.json';
|
|
|
|
|
import blockNameify from '../../../utils/blockNameify';
|
|
|
|
|
import { FullWidthRow } from '../../../helperComponents';
|
|
|
|
|
import { Link } from '../../../Router';
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
|
challengeIdToNameMapSelector,
|
|
|
|
|
userByNameSelector,
|
|
|
|
|
(
|
|
|
|
|
idToNameMap,
|
2018-05-15 14:56:26 +01:00
|
|
|
{ completedChallenges: completedMap = [] }
|
2018-02-19 20:32:14 +00:00
|
|
|
) => ({
|
|
|
|
|
completedMap,
|
2018-05-15 14:56:26 +01:00
|
|
|
idToNameMap
|
2018-02-19 20:32:14 +00:00
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const propTypes = {
|
2018-05-15 14:56:26 +01:00
|
|
|
completedMap: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
|
|
|
|
id: PropTypes.string,
|
|
|
|
|
completedDate: PropTypes.number,
|
|
|
|
|
challengeType: PropTypes.number
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
idToNameMap: PropTypes.objectOf(PropTypes.string)
|
2018-02-19 20:32:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Timeline extends PureComponent {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.renderCompletion = this.renderCompletion.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderCompletion(completed) {
|
|
|
|
|
const { idToNameMap } = this.props;
|
2018-05-15 14:56:26 +01:00
|
|
|
const { id, completedDate } = completed;
|
2018-02-19 20:32:14 +00:00
|
|
|
return (
|
|
|
|
|
<tr key={ id }>
|
|
|
|
|
<td>{ blockNameify(idToNameMap[id]) }</td>
|
|
|
|
|
<td>
|
|
|
|
|
<time dateTime={ format(completedDate, 'YYYY-MM-DDTHH:MM:SSZ') }>
|
|
|
|
|
{
|
|
|
|
|
format(completedDate, 'MMMM DD YYYY')
|
|
|
|
|
}
|
|
|
|
|
</time>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-05-15 14:56:26 +01:00
|
|
|
const { completedMap, idToNameMap } = this.props;
|
2018-02-19 20:32:14 +00:00
|
|
|
if (!Object.keys(idToNameMap).length) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<FullWidthRow>
|
|
|
|
|
<h2 className='text-center'>Timeline</h2>
|
|
|
|
|
{
|
2018-05-15 14:56:26 +01:00
|
|
|
completedMap.length === 0 ?
|
2018-02-19 20:32:14 +00:00
|
|
|
<p className='text-center'>
|
|
|
|
|
No challenges have been completed yet.
|
|
|
|
|
<Link to={ homeURL }>
|
|
|
|
|
Get started here.
|
|
|
|
|
</Link>
|
|
|
|
|
</p> :
|
|
|
|
|
<Table condensed={true} striped={true}>
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Challenge</th>
|
|
|
|
|
<th>First Completed</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{
|
|
|
|
|
reverse(
|
|
|
|
|
sortBy(
|
2018-05-15 14:56:26 +01:00
|
|
|
completedMap,
|
2018-02-19 20:32:14 +00:00
|
|
|
[ 'completedDate' ]
|
2018-05-15 14:56:26 +01:00
|
|
|
).filter(({id}) => id in idToNameMap)
|
2018-02-19 20:32:14 +00:00
|
|
|
)
|
|
|
|
|
.map(this.renderCompletion)
|
|
|
|
|
}
|
|
|
|
|
</tbody>
|
|
|
|
|
</Table>
|
|
|
|
|
}
|
|
|
|
|
</FullWidthRow>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timeline.displayName = 'Timeline';
|
|
|
|
|
Timeline.propTypes = propTypes;
|
|
|
|
|
|
2018-05-15 06:12:05 +01:00
|
|
|
export default connect(mapStateToProps)(Timeline);
|