2016-03-22 22:13:05 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-05-10 21:25:12 -07:00
|
|
|
import { connect } from 'react-redux';
|
2016-06-22 14:55:35 -07:00
|
|
|
import { createSelector } from 'reselect';
|
2016-03-22 22:13:05 -07:00
|
|
|
import FA from 'react-fontawesome';
|
|
|
|
import PureComponent from 'react-pure-render/component';
|
|
|
|
import { Panel } from 'react-bootstrap';
|
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
import Challenge from './Challenge.jsx';
|
|
|
|
import { toggleThisPanel } from '../../redux/actions';
|
2016-03-22 22:13:05 -07:00
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
const dispatchActions = { toggleThisPanel };
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
(_, props) => props.dashedName,
|
|
|
|
state => state.entities.block,
|
|
|
|
state => state.entities.challenge,
|
|
|
|
(state, props) => state.challengesApp.mapUi[props.dashedName],
|
|
|
|
(dashedName, blockMap, challengeMap, isOpen) => {
|
|
|
|
const block = blockMap[dashedName];
|
|
|
|
return {
|
|
|
|
isOpen,
|
|
|
|
dashedName,
|
|
|
|
title: block.title,
|
|
|
|
time: block.time,
|
|
|
|
challenges: block.challenges
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2016-05-10 21:25:12 -07:00
|
|
|
export class Block extends PureComponent {
|
2016-06-22 14:55:35 -07:00
|
|
|
constructor(...props) {
|
|
|
|
super(...props);
|
|
|
|
this.handleSelect = this.handleSelect.bind(this);
|
|
|
|
}
|
2016-03-22 22:13:05 -07:00
|
|
|
static displayName = 'Block';
|
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
2016-06-09 16:02:51 -07:00
|
|
|
dashedName: PropTypes.string,
|
2016-03-22 22:13:05 -07:00
|
|
|
time: PropTypes.string,
|
2016-06-22 14:55:35 -07:00
|
|
|
isOpen: PropTypes.bool,
|
2016-05-09 13:42:39 -07:00
|
|
|
challenges: PropTypes.array,
|
2016-06-22 14:55:35 -07:00
|
|
|
toggleThisPanel: PropTypes.func
|
2016-03-22 22:13:05 -07:00
|
|
|
};
|
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
handleSelect(eventKey, e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.toggleThisPanel(eventKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderChallenges(challenges) {
|
2016-03-22 22:13:05 -07:00
|
|
|
if (!Array.isArray(challenges) || !challenges.length) {
|
|
|
|
return <div>No Challenges Found</div>;
|
|
|
|
}
|
2016-06-22 14:55:35 -07:00
|
|
|
return challenges.map(dashedName => (
|
|
|
|
<Challenge
|
|
|
|
dashedName={ dashedName }
|
|
|
|
key={ dashedName }
|
|
|
|
/>
|
|
|
|
));
|
2016-03-22 22:13:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-06-09 16:02:51 -07:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
time,
|
2016-06-22 14:55:35 -07:00
|
|
|
dashedName,
|
|
|
|
isOpen,
|
|
|
|
challenges
|
2016-06-09 16:02:51 -07:00
|
|
|
} = this.props;
|
2016-03-22 22:13:05 -07:00
|
|
|
return (
|
|
|
|
<Panel
|
|
|
|
bsClass='map-accordion-panel-nested'
|
|
|
|
collapsible={ true }
|
2016-06-22 14:55:35 -07:00
|
|
|
eventKey={ dashedName || title }
|
|
|
|
expanded={ isOpen }
|
2016-03-22 22:13:05 -07:00
|
|
|
header={
|
|
|
|
<div>
|
|
|
|
<h3><FA name='caret-right' />{ title }</h3>
|
|
|
|
<span className='challenge-block-time'>({ time })</span>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
id={ title }
|
2016-06-09 16:02:51 -07:00
|
|
|
key={ title }
|
2016-06-22 14:55:35 -07:00
|
|
|
onSelect={ this.handleSelect }
|
2016-06-09 16:02:51 -07:00
|
|
|
>
|
2016-06-22 14:55:35 -07:00
|
|
|
{ this.renderChallenges(challenges) }
|
2016-03-22 22:13:05 -07:00
|
|
|
</Panel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 21:25:12 -07:00
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
export default connect(mapStateToProps, dispatchActions)(Block);
|