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

87 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-03-21 15:39:45 -07:00
import React, { PropTypes } from 'react';
import { compose } from 'redux';
2016-05-04 16:46:19 -07:00
import { contain } from 'redux-epic';
2016-03-21 15:39:45 -07:00
import { connect } from 'react-redux';
import PureComponent from 'react-pure-render/component';
import { createSelector } from 'reselect';
import Map from './Map.jsx';
2016-03-23 16:19:16 -07:00
import {
clearFilter,
updateFilter,
fetchChallenges
} from '../../redux/actions';
2016-03-21 15:39:45 -07:00
const bindableActions = {
2016-03-23 16:19:16 -07:00
clearFilter,
fetchChallenges,
2016-05-10 21:25:12 -07:00
updateFilter
};
const superBlocksSelector = createSelector(
state => state.challengesApp.superBlocks,
2016-03-21 15:39:45 -07:00
state => state.entities.superBlock,
state => state.entities.block,
state => state.entities.challenge,
(superBlocks, superBlockMap, blockMap, challengeMap) => {
if (!superBlockMap || !blockMap || !challengeMap) {
return {
superBlocks: []
};
}
2016-05-06 16:04:23 -07:00
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,
2016-05-06 16:04:23 -07:00
({ superBlocks }, filter) => {
2016-03-21 15:39:45 -07:00
return {
superBlocks,
filter
2016-03-21 15:39:45 -07:00
};
}
);
2016-03-21 15:39:45 -07:00
const fetchOptions = {
fetchAction: 'fetchChallenges',
isPrimed({ superBlocks }) {
return Array.isArray(superBlocks) && superBlocks.length > 1;
2016-03-21 15:39:45 -07:00
}
};
export class ShowMap extends PureComponent {
static displayName = 'ShowMap';
static propTypes = {
2016-03-23 16:19:16 -07:00
clearFilter: PropTypes.func,
filter: PropTypes.string,
superBlocks: PropTypes.array,
2016-05-10 21:25:12 -07:00
updateFilter: PropTypes.func
2016-03-21 15:39:45 -07:00
};
render() {
return (
<Map { ...this.props } />
2016-03-21 15:39:45 -07:00
);
}
}
export default compose(
connect(mapStateToProps, bindableActions),
contain(fetchOptions)
)(ShowMap);