committed by
Mrugesh Mohapatra
parent
f962d7774a
commit
54a9f70574
@ -6,6 +6,7 @@ import { createSelector } from 'reselect';
|
|||||||
import Link, { navigateTo } from 'gatsby-link';
|
import Link, { navigateTo } from 'gatsby-link';
|
||||||
|
|
||||||
import { makeExpandedBlockSelector, toggleBlock } from '../redux';
|
import { makeExpandedBlockSelector, toggleBlock } from '../redux';
|
||||||
|
import { toggleMapModal } from '../../../redux/app';
|
||||||
import Caret from '../../icons/Caret';
|
import Caret from '../../icons/Caret';
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
@ -17,13 +18,14 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch =>
|
const mapDispatchToProps = dispatch =>
|
||||||
bindActionCreators({ toggleBlock }, dispatch);
|
bindActionCreators({ toggleBlock, toggleMapModal }, dispatch);
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
blockDashedName: PropTypes.string,
|
blockDashedName: PropTypes.string,
|
||||||
challenges: PropTypes.array,
|
challenges: PropTypes.array,
|
||||||
isExpanded: PropTypes.bool,
|
isExpanded: PropTypes.bool,
|
||||||
toggleBlock: PropTypes.func.isRequired
|
toggleBlock: PropTypes.func.isRequired,
|
||||||
|
toggleMapModal: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Block extends PureComponent {
|
export class Block extends PureComponent {
|
||||||
@ -31,6 +33,7 @@ export class Block extends PureComponent {
|
|||||||
super(...props);
|
super(...props);
|
||||||
|
|
||||||
this.handleBlockClick = this.handleBlockClick.bind(this);
|
this.handleBlockClick = this.handleBlockClick.bind(this);
|
||||||
|
this.handleChallengeClick = this.handleChallengeClick.bind(this);
|
||||||
this.renderChallenges = this.renderChallenges.bind(this);
|
this.renderChallenges = this.renderChallenges.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,11 +47,17 @@ export class Block extends PureComponent {
|
|||||||
return navigateTo(blockPath);
|
return navigateTo(blockPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleChallengeClick() {
|
||||||
|
this.props.toggleMapModal();
|
||||||
|
}
|
||||||
|
|
||||||
renderChallenges(challenges) {
|
renderChallenges(challenges) {
|
||||||
// TODO: Split this into a Challenge Component and add tests
|
// TODO: Split this into a Challenge Component and add tests
|
||||||
return challenges.map(challenge => (
|
return challenges.map(challenge => (
|
||||||
<li className='map-challenge-title' key={challenge.dashedName}>
|
<li className='map-challenge-title' key={challenge.dashedName}>
|
||||||
<Link to={challenge.fields.slug}>{challenge.title}</Link>
|
<Link onClick={this.handleChallengeClick} to={challenge.fields.slug}>
|
||||||
|
{challenge.title}
|
||||||
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,14 @@ const renderer = new ShallowRenderer();
|
|||||||
|
|
||||||
test('<Block /> not expanded snapshot', () => {
|
test('<Block /> not expanded snapshot', () => {
|
||||||
const toggleSpy = sinon.spy();
|
const toggleSpy = sinon.spy();
|
||||||
|
const toggleMapSpy = sinon.spy();
|
||||||
const componentToRender = (
|
const componentToRender = (
|
||||||
<Block
|
<Block
|
||||||
blockDashedName='block-a'
|
blockDashedName='block-a'
|
||||||
challenges={mockNodes.filter(node => node.block === 'block-a')}
|
challenges={mockNodes.filter(node => node.block === 'block-a')}
|
||||||
isExpanded={false}
|
isExpanded={false}
|
||||||
toggleBlock={toggleSpy}
|
toggleBlock={toggleSpy}
|
||||||
|
toggleMapModal={toggleMapSpy}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const component = renderer.render(componentToRender);
|
const component = renderer.render(componentToRender);
|
||||||
@ -29,12 +31,14 @@ test('<Block /> not expanded snapshot', () => {
|
|||||||
|
|
||||||
test('<Block expanded snapshot', () => {
|
test('<Block expanded snapshot', () => {
|
||||||
const toggleSpy = sinon.spy();
|
const toggleSpy = sinon.spy();
|
||||||
|
const toggleMapSpy = sinon.spy();
|
||||||
const componentToRender = (
|
const componentToRender = (
|
||||||
<Block
|
<Block
|
||||||
blockDashedName='block-a'
|
blockDashedName='block-a'
|
||||||
challenges={mockNodes.filter(node => node.block === 'block-a')}
|
challenges={mockNodes.filter(node => node.block === 'block-a')}
|
||||||
isExpanded={true}
|
isExpanded={true}
|
||||||
toggleBlock={toggleSpy}
|
toggleBlock={toggleSpy}
|
||||||
|
toggleMapModal={toggleMapSpy}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -45,11 +49,13 @@ test('<Block expanded snapshot', () => {
|
|||||||
|
|
||||||
test('<Block /> should handle toggle clicks correctly', () => {
|
test('<Block /> should handle toggle clicks correctly', () => {
|
||||||
const toggleSpy = sinon.spy();
|
const toggleSpy = sinon.spy();
|
||||||
|
const toggleMapSpy = sinon.spy();
|
||||||
const props = {
|
const props = {
|
||||||
blockDashedName: 'block-a',
|
blockDashedName: 'block-a',
|
||||||
challenges: mockNodes.filter(node => node.block === 'block-a'),
|
challenges: mockNodes.filter(node => node.block === 'block-a'),
|
||||||
isExpanded: false,
|
isExpanded: false,
|
||||||
toggleBlock: toggleSpy
|
toggleBlock: toggleSpy,
|
||||||
|
toggleMapModal: toggleMapSpy
|
||||||
};
|
};
|
||||||
|
|
||||||
const componentToRender = <Block {...props} />;
|
const componentToRender = <Block {...props} />;
|
||||||
|
@ -35,6 +35,7 @@ exports[`<Block expanded snapshot: block-expanded 1`] = `
|
|||||||
className="map-challenge-title"
|
className="map-challenge-title"
|
||||||
>
|
>
|
||||||
<Unknown
|
<Unknown
|
||||||
|
onClick={[Function]}
|
||||||
to="/super-block-one/block-a/challenge-one"
|
to="/super-block-one/block-a/challenge-one"
|
||||||
>
|
>
|
||||||
Challenge One
|
Challenge One
|
||||||
@ -44,6 +45,7 @@ exports[`<Block expanded snapshot: block-expanded 1`] = `
|
|||||||
className="map-challenge-title"
|
className="map-challenge-title"
|
||||||
>
|
>
|
||||||
<Unknown
|
<Unknown
|
||||||
|
onClick={[Function]}
|
||||||
to="/super-block-one/block-a/challenge-two"
|
to="/super-block-one/block-a/challenge-two"
|
||||||
>
|
>
|
||||||
Challenge Two
|
Challenge Two
|
||||||
@ -53,6 +55,7 @@ exports[`<Block expanded snapshot: block-expanded 1`] = `
|
|||||||
className="map-challenge-title"
|
className="map-challenge-title"
|
||||||
>
|
>
|
||||||
<Unknown
|
<Unknown
|
||||||
|
onClick={[Function]}
|
||||||
to="/super-block-one/block-a/challenge-one"
|
to="/super-block-one/block-a/challenge-one"
|
||||||
>
|
>
|
||||||
Challenge One
|
Challenge One
|
||||||
@ -62,6 +65,7 @@ exports[`<Block expanded snapshot: block-expanded 1`] = `
|
|||||||
className="map-challenge-title"
|
className="map-challenge-title"
|
||||||
>
|
>
|
||||||
<Unknown
|
<Unknown
|
||||||
|
onClick={[Function]}
|
||||||
to="/super-block-one/block-a/challenge-two"
|
to="/super-block-one/block-a/challenge-two"
|
||||||
>
|
>
|
||||||
Challenge Two
|
Challenge Two
|
||||||
|
@ -11,6 +11,8 @@ import { toggleMapModal, isMapModalOpenSelector } from '../../redux/app';
|
|||||||
|
|
||||||
import Spacer from '../util/Spacer';
|
import Spacer from '../util/Spacer';
|
||||||
|
|
||||||
|
import './map-modal.css';
|
||||||
|
|
||||||
const mapStateToProps = createSelector(isMapModalOpenSelector, show => ({
|
const mapStateToProps = createSelector(isMapModalOpenSelector, show => ({
|
||||||
show
|
show
|
||||||
}));
|
}));
|
||||||
|
@ -12,9 +12,7 @@ const propTypes = {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
function SuperBlockIntroductionPage(
|
function SuperBlockIntroductionPage({ data: { markdownRemark } }) {
|
||||||
{ data: { markdownRemark } }
|
|
||||||
) {
|
|
||||||
const { html, frontmatter: { superBlock } } = markdownRemark;
|
const { html, frontmatter: { superBlock } } = markdownRemark;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
Reference in New Issue
Block a user