2016-03-22 22:13:05 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-06-22 14:55:35 -07:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createSelector } from 'reselect';
|
2016-03-22 22:13:05 -07:00
|
|
|
import PureComponent from 'react-pure-render/component';
|
|
|
|
import FA from 'react-fontawesome';
|
|
|
|
import { Panel } from 'react-bootstrap';
|
|
|
|
|
|
|
|
import Block from './Block.jsx';
|
2016-06-22 14:55:35 -07:00
|
|
|
import { toggleThisPanel } from '../../redux/actions';
|
2016-03-22 22:13:05 -07:00
|
|
|
|
2016-06-22 14:55:35 -07:00
|
|
|
const dispatchActions = { toggleThisPanel };
|
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
(_, props) => props.dashedName,
|
|
|
|
state => state.entities.superBlock,
|
|
|
|
(state, props) => state.challengesApp.mapUi[props.dashedName],
|
|
|
|
(dashedName, superBlockMap, isOpen) => ({
|
|
|
|
isOpen,
|
|
|
|
title: superBlockMap[dashedName].title,
|
|
|
|
blocks: superBlockMap[dashedName].blocks
|
|
|
|
})
|
|
|
|
);
|
|
|
|
export class SuperBlock extends PureComponent {
|
|
|
|
constructor(...props) {
|
|
|
|
super(...props);
|
|
|
|
this.handleSelect = this.handleSelect.bind(this);
|
2016-06-21 16:28:13 -07:00
|
|
|
}
|
2016-03-22 22:13:05 -07:00
|
|
|
static displayName = 'SuperBlock';
|
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
2016-06-21 16:28:13 -07:00
|
|
|
dashedName: PropTypes.string,
|
|
|
|
blocks: PropTypes.array,
|
2016-06-22 14:55:35 -07:00
|
|
|
isOpen: PropTypes.bool,
|
|
|
|
message: PropTypes.string,
|
2016-06-21 16:28:13 -07:00
|
|
|
toggleThisPanl: PropTypes.func
|
2016-03-22 22:13:05 -07:00
|
|
|
};
|
|
|
|
|
2016-06-21 16:28:13 -07:00
|
|
|
handleSelect(eventKey, e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.toggleThisPanel(eventKey);
|
|
|
|
}
|
|
|
|
|
2016-03-22 22:13:05 -07:00
|
|
|
renderBlocks(blocks) {
|
|
|
|
if (!Array.isArray(blocks) || !blocks.length) {
|
|
|
|
return <div>No Blocks Found</div>;
|
|
|
|
}
|
2016-06-22 14:55:35 -07:00
|
|
|
return blocks.map(dashedName => (
|
|
|
|
<Block
|
|
|
|
dashedName={ dashedName }
|
|
|
|
key={ dashedName }
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
renderMessage(message) {
|
|
|
|
if (!message) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className='challenge-block-description'>
|
|
|
|
{ message }
|
|
|
|
</div>
|
|
|
|
);
|
2016-03-22 22:13:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-06-22 14:55:35 -07:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
dashedName,
|
|
|
|
blocks,
|
|
|
|
message,
|
|
|
|
isOpen
|
|
|
|
} = this.props;
|
2016-03-22 22:13:05 -07:00
|
|
|
return (
|
|
|
|
<Panel
|
|
|
|
bsClass='map-accordion-panel'
|
|
|
|
collapsible={ true }
|
2016-06-21 16:28:13 -07:00
|
|
|
eventKey={ dashedName || title }
|
2016-06-22 14:55:35 -07:00
|
|
|
expanded={ isOpen }
|
2016-03-22 22:13:05 -07:00
|
|
|
header={ <h2><FA name='caret-right' />{ title }</h2> }
|
|
|
|
id={ title }
|
2016-06-21 16:28:13 -07:00
|
|
|
key={ dashedName || title }
|
|
|
|
onSelect={ this.handleSelect }
|
2016-06-09 16:02:51 -07:00
|
|
|
>
|
2016-06-22 14:55:35 -07:00
|
|
|
{ this.renderMessage(message) }
|
2016-03-22 22:13:05 -07:00
|
|
|
<div
|
2016-06-09 16:02:51 -07:00
|
|
|
className='map-accordion-block'
|
|
|
|
>
|
2016-03-22 22:13:05 -07:00
|
|
|
{ this.renderBlocks(blocks) }
|
|
|
|
</div>
|
|
|
|
</Panel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-22 14:55:35 -07:00
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
dispatchActions
|
|
|
|
)(SuperBlock);
|