| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  | import React, { PropTypes } from 'react'; | 
					
						
							| 
									
										
										
										
											2016-06-21 12:36:51 -07:00
										 |  |  | import { compose } from 'redux'; | 
					
						
							|  |  |  | import { contain } from 'redux-epic'; | 
					
						
							|  |  |  | import { connect } from 'react-redux'; | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  | import { createSelector } from 'reselect'; | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  | import PureComponent from 'react-pure-render/component'; | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  | import { Col } from 'react-bootstrap'; | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 12:36:51 -07:00
										 |  |  | import MapHeader from './Header.jsx'; | 
					
						
							| 
									
										
										
										
											2016-03-22 22:13:05 -07:00
										 |  |  | import SuperBlock from './Super-Block.jsx'; | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  | import { fetchChallenges } from '../../redux/actions'; | 
					
						
							| 
									
										
										
										
											2016-07-20 16:30:39 -07:00
										 |  |  | import { updateTitle } from '../../../../redux/actions'; | 
					
						
							| 
									
										
										
										
											2016-06-21 12:36:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 16:30:39 -07:00
										 |  |  | const bindableActions = { fetchChallenges, updateTitle }; | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  | const mapStateToProps = createSelector( | 
					
						
							|  |  |  |   state => state.app.windowHeight, | 
					
						
							|  |  |  |   state => state.app.navHeight, | 
					
						
							|  |  |  |   state => state.challengesApp.superBlocks, | 
					
						
							|  |  |  |   (windowHeight, navHeight, superBlocks) => ({ | 
					
						
							|  |  |  |     superBlocks, | 
					
						
							|  |  |  |     height: windowHeight - navHeight - 150 | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2016-06-21 12:36:51 -07:00
										 |  |  | const fetchOptions = { | 
					
						
							|  |  |  |   fetchAction: 'fetchChallenges', | 
					
						
							|  |  |  |   isPrimed({ superBlocks }) { | 
					
						
							|  |  |  |     return Array.isArray(superBlocks) && superBlocks.length > 1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | export class ShowMap extends PureComponent { | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  |   static displayName = 'Map'; | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  |   static propTypes = { | 
					
						
							|  |  |  |     superBlocks: PropTypes.array, | 
					
						
							| 
									
										
										
										
											2016-07-20 16:30:39 -07:00
										 |  |  |     height: PropTypes.number, | 
					
						
							|  |  |  |     updateTitle: PropTypes.func.isRequired, | 
					
						
							| 
									
										
										
										
											2016-09-02 22:09:21 -07:00
										 |  |  |     params: PropTypes.object, | 
					
						
							| 
									
										
										
										
											2016-07-20 16:30:39 -07:00
										 |  |  |     fetchChallenges: PropTypes.func.isRequired | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 16:30:39 -07:00
										 |  |  |   componentWillMount() { | 
					
						
							| 
									
										
										
										
											2016-08-05 20:51:52 -07:00
										 |  |  |     // if no params then map is open in drawer
 | 
					
						
							|  |  |  |     // do not update title
 | 
					
						
							|  |  |  |     if (!this.props.params) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-20 16:30:39 -07:00
										 |  |  |     this.props.updateTitle( | 
					
						
							|  |  |  |       'A Map to Learn to Code and Become a Software Engineer' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |   renderSuperBlocks(superBlocks) { | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  |     if (!Array.isArray(superBlocks) || !superBlocks.length) { | 
					
						
							|  |  |  |       return <div>No Super Blocks</div>; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |     return superBlocks.map(dashedName => ( | 
					
						
							|  |  |  |       <SuperBlock | 
					
						
							|  |  |  |         dashedName={ dashedName } | 
					
						
							|  |  |  |         key={ dashedName } | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     )); | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2016-10-06 15:06:18 -05:00
										 |  |  |     const { superBlocks } = this.props; | 
					
						
							|  |  |  |     let height = 'auto'; | 
					
						
							|  |  |  |     if (!this.props.params) { | 
					
						
							|  |  |  |       height = this.props.height + 'px'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  |       <Col xs={ 12 }> | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |         <MapHeader /> | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  |         <div | 
					
						
							|  |  |  |           className='map-accordion center-block' | 
					
						
							| 
									
										
										
										
											2016-10-06 15:06:18 -05:00
										 |  |  |           style={{ height: height }} | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  |           > | 
					
						
							| 
									
										
										
										
											2016-06-22 14:55:35 -07:00
										 |  |  |           { this.renderSuperBlocks(superBlocks) } | 
					
						
							| 
									
										
										
										
											2016-06-21 16:28:13 -07:00
										 |  |  |           <div className='spacer' /> | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2016-06-23 15:51:22 -07:00
										 |  |  |       </Col> | 
					
						
							| 
									
										
										
										
											2016-03-21 15:39:45 -07:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-21 12:36:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default compose( | 
					
						
							|  |  |  |   connect(mapStateToProps, bindableActions), | 
					
						
							|  |  |  |   contain(fetchOptions) | 
					
						
							|  |  |  | )(ShowMap); |