Files
freeCodeCamp/common/app/routes/challenges/components/map/Map.jsx

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-03-21 15:39:45 -07:00
import React, { PropTypes } from 'react';
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';
import MapHeader from './Header.jsx';
import SuperBlock from './Super-Block.jsx';
import { fetchChallenges } from '../../redux/actions';
const bindableActions = { fetchChallenges };
const mapStateToProps = state => ({
superBlocks: state.challengesApp.superBlocks
});
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';
static propTypes = { superBlocks: PropTypes.array };
2016-03-21 15:39:45 -07:00
renderSuperBlocks(superBlocks) {
2016-03-21 15:39:45 -07:00
if (!Array.isArray(superBlocks) || !superBlocks.length) {
return <div>No Super Blocks</div>;
}
return superBlocks.map(dashedName => (
<SuperBlock
dashedName={ dashedName }
key={ dashedName }
/>
));
2016-03-21 15:39:45 -07:00
}
render() {
const { superBlocks } = this.props;
2016-03-21 15:39:45 -07:00
return (
<div>
<MapHeader />
2016-06-21 16:28:13 -07:00
<div className='map-accordion'>
{ this.renderSuperBlocks(superBlocks) }
2016-06-21 16:28:13 -07:00
<div className='spacer' />
2016-03-21 15:39:45 -07:00
</div>
</div>
);
}
}
export default compose(
connect(mapStateToProps, bindableActions),
contain(fetchOptions)
)(ShowMap);