import React, { PropTypes } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import FA from 'react-fontawesome'; import PureComponent from 'react-pure-render/component'; import { Panel } from 'react-bootstrap'; import Challenge from './Challenge.jsx'; import { toggleThisPanel } from '../../redux/actions'; const dispatchActions = { toggleThisPanel }; const mapStateToProps = createSelector( (_, props) => props.dashedName, (state, props) => state.entities.block[props.dashedName], state => state.entities.challenge, (state, props) => state.challengesApp.mapUi[props.dashedName], (dashedName, block, challengeMap, isOpen) => { return { isOpen, dashedName, title: block.title, time: block.time, challenges: block.challenges }; } ); export class Block extends PureComponent { constructor(...props) { super(...props); this.handleSelect = this.handleSelect.bind(this); } static displayName = 'Block'; static propTypes = { title: PropTypes.string, dashedName: PropTypes.string, time: PropTypes.string, isOpen: PropTypes.bool, challenges: PropTypes.array, toggleThisPanel: PropTypes.func }; handleSelect(eventKey, e) { e.preventDefault(); this.props.toggleThisPanel(eventKey); } renderHeader(isOpen, title, time, isCompleted) { return (

{ title } ({ time })

); } renderChallenges(challenges) { if (!Array.isArray(challenges) || !challenges.length) { return
No Challenges Found
; } return challenges.map(dashedName => ( )); } render() { const { title, time, dashedName, isOpen, challenges } = this.props; return ( { this.renderChallenges(challenges) } ); } } export default connect(mapStateToProps, dispatchActions)(Block);