2016-03-21 15:39:45 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-06-21 12:36:51 -07:00
|
|
|
import { compose } from 'redux';
|
|
|
|
import { contain } from 'redux-epic';
|
|
|
|
import { connect } from 'react-redux';
|
2016-03-21 15:39:45 -07:00
|
|
|
import PureComponent from 'react-pure-render/component';
|
|
|
|
|
2016-06-21 12:36:51 -07:00
|
|
|
import MapHeader from './Header.jsx';
|
2016-03-22 22:13:05 -07:00
|
|
|
import SuperBlock from './Super-Block.jsx';
|
2016-06-22 14:55:35 -07:00
|
|
|
import { fetchChallenges } from '../../redux/actions';
|
2016-06-21 12:36:51 -07:00
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
const bindableActions = { fetchChallenges };
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
superBlocks: state.challengesApp.superBlocks
|
|
|
|
});
|
2016-06-21 12:36:51 -07:00
|
|
|
const fetchOptions = {
|
|
|
|
fetchAction: 'fetchChallenges',
|
|
|
|
isPrimed({ superBlocks }) {
|
|
|
|
return Array.isArray(superBlocks) && superBlocks.length > 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
export class ShowMap extends PureComponent {
|
2016-03-21 15:39:45 -07:00
|
|
|
static displayName = 'Map';
|
2016-06-22 14:55:35 -07:00
|
|
|
static propTypes = { superBlocks: PropTypes.array };
|
2016-03-21 15:39:45 -07:00
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
renderSuperBlocks(superBlocks) {
|
2016-03-21 15:39:45 -07:00
|
|
|
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
|
|
|
return <div>No Super Blocks</div>;
|
|
|
|
}
|
2016-06-22 14:55:35 -07:00
|
|
|
return superBlocks.map(dashedName => (
|
|
|
|
<SuperBlock
|
|
|
|
dashedName={ dashedName }
|
|
|
|
key={ dashedName }
|
|
|
|
/>
|
|
|
|
));
|
2016-03-21 15:39:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-06-22 14:55:35 -07:00
|
|
|
const { superBlocks } = this.props;
|
2016-03-21 15:39:45 -07:00
|
|
|
return (
|
|
|
|
<div>
|
2016-06-22 14:55:35 -07:00
|
|
|
<MapHeader />
|
2016-06-21 16:28:13 -07:00
|
|
|
<div className='map-accordion'>
|
2016-06-22 14:55:35 -07:00
|
|
|
{ this.renderSuperBlocks(superBlocks) }
|
2016-06-21 16:28:13 -07:00
|
|
|
<div className='spacer' />
|
2016-03-21 15:39:45 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-21 12:36:51 -07:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
connect(mapStateToProps, bindableActions),
|
|
|
|
contain(fetchOptions)
|
|
|
|
)(ShowMap);
|