feature(map): Add collapse to block level
This commit is contained in:
@@ -2,141 +2,45 @@ import React, { PropTypes } from 'react';
|
||||
import { compose } from 'redux';
|
||||
import { contain } from 'redux-epic';
|
||||
import { connect } from 'react-redux';
|
||||
import { createSelector } from 'reselect';
|
||||
import PureComponent from 'react-pure-render/component';
|
||||
|
||||
import MapHeader from './Header.jsx';
|
||||
import SuperBlock from './Super-Block.jsx';
|
||||
import FullStack from './Full-Stack.jsx';
|
||||
import CodingPrep from './Coding-Prep.jsx';
|
||||
import {
|
||||
clearFilter,
|
||||
fetchChallenges,
|
||||
toggleThisPanel,
|
||||
updateFilter
|
||||
} from '../../redux/actions';
|
||||
|
||||
const bindableActions = {
|
||||
clearFilter,
|
||||
fetchChallenges,
|
||||
toggleThisPanel,
|
||||
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,
|
||||
state => state.challengesApp.map,
|
||||
({ superBlocks }, filter, mapUi) => {
|
||||
return {
|
||||
superBlocks,
|
||||
filter,
|
||||
mapUi
|
||||
};
|
||||
}
|
||||
);
|
||||
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 {
|
||||
static displayName = 'Map';
|
||||
static propTypes = {
|
||||
clearFilter: PropTypes.func,
|
||||
filter: PropTypes.string,
|
||||
superBlocks: PropTypes.array,
|
||||
updateFilter: PropTypes.func,
|
||||
mapUi: PropTypes.object
|
||||
};
|
||||
static propTypes = { superBlocks: PropTypes.array };
|
||||
|
||||
renderSuperBlocks(
|
||||
superBlocks,
|
||||
updateCurrentChallenge,
|
||||
mapUi,
|
||||
toggleThisPanel
|
||||
) {
|
||||
renderSuperBlocks(superBlocks) {
|
||||
if (!Array.isArray(superBlocks) || !superBlocks.length) {
|
||||
return <div>No Super Blocks</div>;
|
||||
}
|
||||
return superBlocks
|
||||
.map((superBlock) => {
|
||||
return (
|
||||
<SuperBlock
|
||||
key={ superBlock.title }
|
||||
mapUi={ mapUi }
|
||||
toggleThisPanel={ toggleThisPanel }
|
||||
updateCurrentChallenge={ updateCurrentChallenge }
|
||||
{ ...superBlock }
|
||||
/>
|
||||
);
|
||||
});
|
||||
return superBlocks.map(dashedName => (
|
||||
<SuperBlock
|
||||
dashedName={ dashedName }
|
||||
key={ dashedName }
|
||||
/>
|
||||
));
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
updateCurrentChallenge,
|
||||
superBlocks,
|
||||
updateFilter,
|
||||
clearFilter,
|
||||
filter,
|
||||
mapUi,
|
||||
toggleThisPanel
|
||||
} = this.props;
|
||||
const { superBlocks } = this.props;
|
||||
return (
|
||||
<div>
|
||||
<MapHeader
|
||||
clearFilter={ clearFilter }
|
||||
filter={ filter }
|
||||
updateFilter={ updateFilter }
|
||||
/>
|
||||
<MapHeader />
|
||||
<div className='map-accordion'>
|
||||
{
|
||||
this.renderSuperBlocks(
|
||||
superBlocks,
|
||||
updateCurrentChallenge,
|
||||
mapUi,
|
||||
toggleThisPanel
|
||||
)
|
||||
}
|
||||
<FullStack
|
||||
mapUi={ mapUi }
|
||||
toggleThisPanel={ toggleThisPanel }
|
||||
/>
|
||||
<CodingPrep
|
||||
mapUi={ mapUi }
|
||||
toggleThisPanel={ toggleThisPanel }
|
||||
/>
|
||||
{ this.renderSuperBlocks(superBlocks) }
|
||||
<div className='spacer' />
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user