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';
|
|
|
|
import { createSelector } from 'reselect';
|
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';
|
|
|
|
import FullStack from './Full-Stack.jsx';
|
|
|
|
import CodingPrep from './Coding-Prep.jsx';
|
2016-06-21 12:36:51 -07:00
|
|
|
import {
|
|
|
|
clearFilter,
|
|
|
|
updateFilter,
|
|
|
|
fetchChallenges
|
|
|
|
} from '../../redux/actions';
|
2016-03-21 15:39:45 -07:00
|
|
|
|
2016-06-21 12:36:51 -07:00
|
|
|
const bindableActions = {
|
|
|
|
clearFilter,
|
|
|
|
fetchChallenges,
|
|
|
|
updateFilter
|
|
|
|
};
|
|
|
|
const superBlocksSelector = createSelector(
|
|
|
|
state => state.challengesApp.superBlocks,
|
|
|
|
state => state.entities.superBlock,
|
|
|
|
state => state.entities.block,
|
|
|
|
state => state.entities.challenge,
|
|
|
|
(superBlocks, superBlockMap, blockMap, challengeMap) => {
|
|
|
|
if (!superBlockMap || !blockMap || !challengeMap) {
|
|
|
|
return {
|
|
|
|
superBlocks: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
superBlocks: superBlocks
|
|
|
|
.map(superBlockName => superBlockMap[superBlockName])
|
|
|
|
.map(superBlock => ({
|
|
|
|
...superBlock,
|
|
|
|
blocks: superBlock.blocks
|
|
|
|
.map(blockName => blockMap[blockName])
|
|
|
|
.map(block => ({
|
|
|
|
...block,
|
|
|
|
challenges: block.challenges
|
|
|
|
.map(dashedName => challengeMap[dashedName])
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
superBlocksSelector,
|
|
|
|
state => state.challengesApp.filter,
|
|
|
|
({ superBlocks }, filter) => {
|
|
|
|
return {
|
|
|
|
superBlocks,
|
|
|
|
filter
|
|
|
|
};
|
2016-06-21 12:15:18 -07:00
|
|
|
}
|
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';
|
|
|
|
static propTypes = {
|
2016-03-23 16:19:16 -07:00
|
|
|
clearFilter: PropTypes.func,
|
2016-03-23 15:01:01 -07:00
|
|
|
filter: PropTypes.string,
|
2016-03-23 16:19:16 -07:00
|
|
|
superBlocks: PropTypes.array,
|
2016-03-23 15:01:01 -07:00
|
|
|
updateFilter: PropTypes.func
|
2016-03-21 15:39:45 -07:00
|
|
|
};
|
|
|
|
|
2016-05-10 21:25:12 -07:00
|
|
|
renderSuperBlocks(superBlocks, updateCurrentChallenge) {
|
2016-03-21 15:39:45 -07:00
|
|
|
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
|
|
|
return <div>No Super Blocks</div>;
|
|
|
|
}
|
|
|
|
return superBlocks.map((superBlock) => {
|
|
|
|
return (
|
2016-03-22 22:13:05 -07:00
|
|
|
<SuperBlock
|
|
|
|
key={ superBlock.title }
|
2016-05-10 21:25:12 -07:00
|
|
|
updateCurrentChallenge={ updateCurrentChallenge }
|
2016-06-21 11:50:58 -07:00
|
|
|
{ ...superBlock }
|
|
|
|
/>
|
2016-03-21 15:39:45 -07:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-05-09 13:42:39 -07:00
|
|
|
const {
|
2016-05-10 21:25:12 -07:00
|
|
|
updateCurrentChallenge,
|
2016-05-09 13:42:39 -07:00
|
|
|
superBlocks,
|
|
|
|
updateFilter,
|
|
|
|
clearFilter,
|
|
|
|
filter
|
|
|
|
} = this.props;
|
2016-03-21 15:39:45 -07:00
|
|
|
return (
|
|
|
|
<div>
|
2016-06-21 12:36:51 -07:00
|
|
|
<MapHeader
|
|
|
|
clearFilter={ clearFilter }
|
|
|
|
filter={ filter }
|
|
|
|
updateFilter={ updateFilter }
|
|
|
|
/>
|
2016-03-21 15:39:45 -07:00
|
|
|
<div
|
2016-06-21 11:50:58 -07:00
|
|
|
className='map-accordion'
|
|
|
|
>
|
2016-05-10 21:25:12 -07:00
|
|
|
{ this.renderSuperBlocks(superBlocks, updateCurrentChallenge) }
|
2016-03-22 22:13:05 -07:00
|
|
|
<FullStack />
|
|
|
|
<CodingPrep />
|
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);
|