2016-03-22 22:13:05 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-06-20 21:01:14 -07:00
|
|
|
import { Link } from 'react-router';
|
2016-05-10 21:25:12 -07:00
|
|
|
import { connect } from 'react-redux';
|
2016-03-22 22:13:05 -07:00
|
|
|
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-03-22 22:13:05 -07:00
|
|
|
|
2016-05-10 21:25:12 -07:00
|
|
|
const dispatchActions = { updateCurrentChallenge };
|
|
|
|
export class Block extends PureComponent {
|
2016-03-22 22:13:05 -07:00
|
|
|
static displayName = 'Block';
|
|
|
|
static propTypes = {
|
|
|
|
title: PropTypes.string,
|
2016-06-09 16:02:51 -07:00
|
|
|
dashedName: PropTypes.string,
|
2016-03-22 22:13:05 -07:00
|
|
|
time: PropTypes.string,
|
2016-05-09 13:42:39 -07:00
|
|
|
challenges: PropTypes.array,
|
2016-05-10 21:25:12 -07:00
|
|
|
updateCurrentChallenge: PropTypes.func
|
2016-03-22 22:13:05 -07:00
|
|
|
};
|
|
|
|
|
2016-06-09 16:02:51 -07:00
|
|
|
renderChallenges(blockName, challenges, updateCurrentChallenge) {
|
2016-03-22 22:13:05 -07:00
|
|
|
if (!Array.isArray(challenges) || !challenges.length) {
|
|
|
|
return <div>No Challenges Found</div>;
|
|
|
|
}
|
|
|
|
return challenges.map(challenge => {
|
2016-06-20 13:38:49 -07:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
dashedName,
|
|
|
|
isLocked,
|
|
|
|
isRequired,
|
|
|
|
isCompleted
|
|
|
|
} = challenge;
|
2016-03-22 22:13:05 -07:00
|
|
|
const challengeClassName = classnames({
|
|
|
|
'text-primary': true,
|
|
|
|
'padded-ionic-icon': true,
|
|
|
|
'negative-15': true,
|
|
|
|
'challenge-title': true,
|
2016-06-20 13:38:49 -07:00
|
|
|
'ion-checkmark-circled faded': !isLocked && isCompleted,
|
|
|
|
'ion-ios-circle-outline': !isLocked && !isCompleted,
|
2016-03-22 22:13:05 -07:00
|
|
|
'ion-locked': isLocked,
|
2016-04-18 19:06:33 -07:00
|
|
|
disabled: isLocked
|
2016-03-22 22:13:05 -07:00
|
|
|
});
|
|
|
|
if (isLocked) {
|
|
|
|
return (
|
|
|
|
<p
|
|
|
|
className={ challengeClassName }
|
2016-06-09 16:02:51 -07:00
|
|
|
key={ title }
|
|
|
|
>
|
2016-03-22 22:13:05 -07:00
|
|
|
{ title }
|
|
|
|
{
|
|
|
|
isRequired ?
|
|
|
|
<span className='text-primary'><strong>*</strong></span> :
|
|
|
|
''
|
|
|
|
}
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<p
|
|
|
|
className={ challengeClassName }
|
2016-06-09 16:02:51 -07:00
|
|
|
key={ title }
|
|
|
|
>
|
2016-06-20 21:01:14 -07:00
|
|
|
<Link to={ `/challenges/${blockName}/${dashedName}` }>
|
2016-05-09 13:42:39 -07:00
|
|
|
<span
|
2016-06-09 16:02:51 -07:00
|
|
|
onClick={ () => updateCurrentChallenge(challenge) }
|
|
|
|
>
|
2016-05-09 13:42:39 -07:00
|
|
|
{ title }
|
|
|
|
<span className='sr-only'>complete</span>
|
|
|
|
{
|
|
|
|
isRequired ?
|
|
|
|
<span className='text-primary'><strong>*</strong></span> :
|
|
|
|
''
|
|
|
|
}
|
|
|
|
</span>
|
2016-06-20 21:01:14 -07:00
|
|
|
</Link>
|
2016-03-22 22:13:05 -07:00
|
|
|
</p>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-06-09 16:02:51 -07:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
time,
|
|
|
|
challenges,
|
|
|
|
updateCurrentChallenge,
|
|
|
|
dashedName
|
|
|
|
} = this.props;
|
2016-03-22 22:13:05 -07:00
|
|
|
return (
|
|
|
|
<Panel
|
|
|
|
bsClass='map-accordion-panel-nested'
|
|
|
|
collapsible={ true }
|
2016-06-21 11:50:58 -07:00
|
|
|
expanded={ false }
|
2016-03-22 22:13:05 -07:00
|
|
|
header={
|
|
|
|
<div>
|
|
|
|
<h3><FA name='caret-right' />{ title }</h3>
|
|
|
|
<span className='challenge-block-time'>({ time })</span>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
id={ title }
|
2016-06-09 16:02:51 -07:00
|
|
|
key={ title }
|
|
|
|
>
|
|
|
|
{
|
|
|
|
this.renderChallenges(dashedName, challenges, updateCurrentChallenge)
|
|
|
|
}
|
2016-03-22 22:13:05 -07:00
|
|
|
</Panel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 21:25:12 -07:00
|
|
|
|
|
|
|
export default connect(null, dispatchActions)(Block);
|