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

113 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-03-21 15:39:45 -07:00
import React, { PropTypes } from 'react';
import classnames from 'classnames';
2016-03-21 15:39:45 -07:00
import PureComponent from 'react-pure-render/component';
import { InputGroup, FormControl, Button, Row } from 'react-bootstrap';
2016-03-21 15:39:45 -07:00
import SuperBlock from './Super-Block.jsx';
import FullStack from './Full-Stack.jsx';
import CodingPrep from './Coding-Prep.jsx';
2016-03-21 15:39:45 -07:00
2016-03-23 16:19:16 -07:00
const clearIcon = <i className='fa fa-times' />;
const searchIcon = <i className='fa fa-search' />;
const ESC = 27;
2016-03-21 15:39:45 -07:00
export default class ShowMap extends PureComponent {
constructor(...props) {
super(...props);
this.handleKeyDown = this.handleKeyDown.bind(this);
}
2016-03-21 15:39:45 -07:00
static displayName = 'Map';
static propTypes = {
2016-03-23 16:19:16 -07:00
clearFilter: PropTypes.func,
filter: PropTypes.string,
2016-03-23 16:19:16 -07:00
superBlocks: PropTypes.array,
updateFilter: PropTypes.func
2016-03-21 15:39:45 -07:00
};
handleKeyDown(e) {
if (e.keyCode === ESC) {
this.props.clearFilter();
}
}
2016-05-10 21:25:12 -07:00
renderSuperBlocks(superBlocks, updateCurrentChallenge) {
2016-03-21 15:39:45 -07:00
if (!Array.isArray(superBlocks) || !superBlocks.length) {
return <div>No Super Blocks</div>;
}
return superBlocks.map((superBlock) => {
return (
<SuperBlock
key={ superBlock.title }
2016-05-10 21:25:12 -07:00
updateCurrentChallenge={ updateCurrentChallenge }
2016-06-21 11:50:58 -07:00
{ ...superBlock }
/>
2016-03-21 15:39:45 -07:00
);
});
}
renderSearchAddon(filter, clearFilter) {
if (!filter) {
return searchIcon;
}
return <span onClick={ clearFilter }>{ clearIcon }</span>;
}
2016-03-21 15:39:45 -07:00
render() {
const {
2016-05-10 21:25:12 -07:00
updateCurrentChallenge,
superBlocks,
updateFilter,
clearFilter,
filter
} = this.props;
const inputClass = classnames({
'map-filter': true,
filled: !!filter
});
2016-03-21 15:39:45 -07:00
return (
<div>
<div className='map-wrapper'>
<div
className='text-center map-fixed-header'
2016-06-21 11:50:58 -07:00
style={{ top: '50px' }}
>
2016-03-21 15:39:45 -07:00
<p>Challenges required for certifications are marked with a *</p>
<Row className='map-buttons'>
<Button
block={ true }
bsStyle='primary'
2016-06-21 11:50:58 -07:00
className='center-block'
>
2016-03-21 15:39:45 -07:00
Collapse all challenges
</Button>
</Row>
<Row className='map-buttons'>
<InputGroup>
<FormControl
autocompleted='off'
className={ inputClass }
onChange={ updateFilter }
onKeyDown={ this.handleKeyDown }
placeholder='Type a challenge name'
type='text'
value={ filter }
/>
<InputGroup.Addon>
{ this.renderSearchAddon(filter, clearFilter) }
</InputGroup.Addon>
</InputGroup>
2016-03-21 15:39:45 -07:00
</Row>
<hr />
</div>
</div>
<div
2016-06-21 11:50:58 -07:00
className='map-accordion'
>
2016-05-10 21:25:12 -07:00
{ this.renderSuperBlocks(superBlocks, updateCurrentChallenge) }
<FullStack />
<CodingPrep />
2016-03-21 15:39:45 -07:00
</div>
</div>
);
}
}