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

93 lines
2.6 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
2016-04-18 19:06:33 -07:00
import { Link } from 'react-router';
2016-05-10 21:25:12 -07:00
import { connect } from 'react-redux';
import FA from 'react-fontawesome';
import PureComponent from 'react-pure-render/component';
import { Panel } from 'react-bootstrap';
import classnames from 'classnames';
2016-05-10 21:25:12 -07:00
import { updateCurrentChallenge } from '../../redux/actions';
2016-05-10 21:25:12 -07:00
const dispatchActions = { updateCurrentChallenge };
export class Block extends PureComponent {
static displayName = 'Block';
static propTypes = {
title: PropTypes.string,
time: PropTypes.string,
challenges: PropTypes.array,
2016-05-10 21:25:12 -07:00
updateCurrentChallenge: PropTypes.func
};
2016-05-10 21:25:12 -07:00
renderChallenges(challenges, updateCurrentChallenge) {
if (!Array.isArray(challenges) || !challenges.length) {
return <div>No Challenges Found</div>;
}
return challenges.map(challenge => {
const { title, dashedName, isLocked, isRequired } = challenge;
const challengeClassName = classnames({
'text-primary': true,
'padded-ionic-icon': true,
'negative-15': true,
'challenge-title': true,
'ion-checkmark-circled': !isLocked,
'ion-locked': isLocked,
2016-04-18 19:06:33 -07:00
disabled: isLocked
});
if (isLocked) {
return (
<p
className={ challengeClassName }
key={ title }>
{ title }
{
isRequired ?
<span className='text-primary'><strong>*</strong></span> :
''
}
</p>
);
}
return (
<p
className={ challengeClassName }
key={ title }>
2016-04-18 19:06:33 -07:00
<Link to={ `/challenges/${dashedName}` }>
<span
2016-05-10 21:25:12 -07:00
onClick={ () => updateCurrentChallenge(challenge) }>
{ title }
<span className='sr-only'>complete</span>
{
isRequired ?
<span className='text-primary'><strong>*</strong></span> :
''
}
</span>
2016-04-18 19:06:33 -07:00
</Link>
</p>
);
});
}
render() {
2016-05-10 21:25:12 -07:00
const { title, time, challenges, updateCurrentChallenge } = this.props;
return (
<Panel
bsClass='map-accordion-panel-nested'
collapsible={ true }
expanded={ true }
header={
<div>
<h3><FA name='caret-right' />{ title }</h3>
<span className='challenge-block-time'>({ time })</span>
</div>
}
id={ title }
key={ title }>
2016-05-10 21:25:12 -07:00
{ this.renderChallenges(challenges, updateCurrentChallenge) }
</Panel>
);
}
}
2016-05-10 21:25:12 -07:00
export default connect(null, dispatchActions)(Block);