| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | import React, { PropTypes } from 'react'; | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  | import { Button, Row } from 'react-bootstrap'; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | import { connect } from 'react-redux'; | 
					
						
							|  |  |  | import { createSelector } from 'reselect'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  | import MapDrawer from './components/Map-Drawer.jsx'; | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  | import { | 
					
						
							|  |  |  |   fetchUser, | 
					
						
							| 
									
										
										
										
											2016-05-11 21:14:08 -07:00
										 |  |  |   initWindowHeight, | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |   updateNavHeight, | 
					
						
							| 
									
										
										
										
											2016-06-03 23:34:28 -07:00
										 |  |  |   toggleMapDrawer, | 
					
						
							| 
									
										
										
										
											2016-07-20 15:06:44 -07:00
										 |  |  |   toggleMainChat, | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  |   updateAppLang, | 
					
						
							| 
									
										
										
										
											2016-08-03 12:56:00 -07:00
										 |  |  |   trackEvent, | 
					
						
							|  |  |  |   loadCurrentChallenge | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  | } from './redux/actions'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  | import { submitChallenge } from './routes/challenges/redux/actions'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 09:33:55 -08:00
										 |  |  | import Nav from './components/Nav'; | 
					
						
							| 
									
										
										
										
											2016-07-06 11:47:16 -07:00
										 |  |  | import Toasts from './toasts/Toasts.jsx'; | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  | import { userSelector } from './redux/selectors'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 15:06:44 -07:00
										 |  |  | const bindableActions = { | 
					
						
							|  |  |  |   initWindowHeight, | 
					
						
							|  |  |  |   updateNavHeight, | 
					
						
							|  |  |  |   fetchUser, | 
					
						
							|  |  |  |   submitChallenge, | 
					
						
							|  |  |  |   toggleMapDrawer, | 
					
						
							|  |  |  |   toggleMainChat, | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  |   updateAppLang, | 
					
						
							| 
									
										
										
										
											2016-08-03 12:56:00 -07:00
										 |  |  |   trackEvent, | 
					
						
							|  |  |  |   loadCurrentChallenge | 
					
						
							| 
									
										
										
										
											2016-07-20 15:06:44 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | const mapStateToProps = createSelector( | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |   userSelector, | 
					
						
							|  |  |  |   state => state.app.shouldShowSignIn, | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |   state => state.app.toast, | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |   state => state.app.isMapDrawerOpen, | 
					
						
							|  |  |  |   state => state.app.isMapAlreadyLoaded, | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |   state => state.challengesApp.toast, | 
					
						
							|  |  |  |   ( | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |     { user: { username, points, picture } }, | 
					
						
							|  |  |  |     shouldShowSignIn, | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |     toast, | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |     isMapDrawerOpen, | 
					
						
							|  |  |  |     isMapAlreadyLoaded, | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |   ) => ({ | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |     username, | 
					
						
							|  |  |  |     points, | 
					
						
							|  |  |  |     picture, | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |     toast, | 
					
						
							| 
									
										
										
										
											2016-06-20 21:01:14 -07:00
										 |  |  |     shouldShowSignIn, | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |     isMapDrawerOpen, | 
					
						
							|  |  |  |     isMapAlreadyLoaded, | 
					
						
							| 
									
										
										
										
											2016-06-20 21:01:14 -07:00
										 |  |  |     isSignedIn: !!username | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |   }) | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // export plain class for testing
 | 
					
						
							|  |  |  | export class FreeCodeCamp extends React.Component { | 
					
						
							|  |  |  |   static displayName = 'FreeCodeCamp'; | 
					
						
							| 
									
										
										
										
											2016-06-27 20:11:52 -07:00
										 |  |  |   static contextTypes = { | 
					
						
							|  |  |  |     router: PropTypes.object | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |   static propTypes = { | 
					
						
							|  |  |  |     children: PropTypes.node, | 
					
						
							|  |  |  |     username: PropTypes.string, | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |     isSignedIn: PropTypes.bool, | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |     points: PropTypes.number, | 
					
						
							|  |  |  |     picture: PropTypes.string, | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  |     toast: PropTypes.object, | 
					
						
							|  |  |  |     updateNavHeight: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |     initWindowHeight: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |     submitChallenge: PropTypes.func, | 
					
						
							|  |  |  |     isMapDrawerOpen: PropTypes.bool, | 
					
						
							|  |  |  |     isMapAlreadyLoaded: PropTypes.bool, | 
					
						
							| 
									
										
										
										
											2016-06-03 23:34:28 -07:00
										 |  |  |     toggleMapDrawer: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |     toggleMainChat: PropTypes.func, | 
					
						
							|  |  |  |     fetchUser: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-06-27 20:11:52 -07:00
										 |  |  |     shouldShowSignIn: PropTypes.bool, | 
					
						
							| 
									
										
										
										
											2016-07-20 15:06:44 -07:00
										 |  |  |     params: PropTypes.object, | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  |     updateAppLang: PropTypes.func.isRequired, | 
					
						
							| 
									
										
										
										
											2016-08-03 12:56:00 -07:00
										 |  |  |     trackEvent: PropTypes.func.isRequired, | 
					
						
							|  |  |  |     loadCurrentChallenge: PropTypes.func.isRequired | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2015-07-29 10:16:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-20 15:06:44 -07:00
										 |  |  |   componentWillReceiveProps(nextProps) { | 
					
						
							|  |  |  |     if (this.props.params.lang !== nextProps.params.lang) { | 
					
						
							|  |  |  |       this.props.updateAppLang(nextProps.params.lang); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  |   componentDidMount() { | 
					
						
							| 
									
										
										
										
											2016-05-11 21:14:08 -07:00
										 |  |  |     this.props.initWindowHeight(); | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |     if (!this.props.isSignedIn) { | 
					
						
							|  |  |  |       this.props.fetchUser(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |   renderChallengeComplete() { | 
					
						
							|  |  |  |     const { submitChallenge } = this.props; | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |       <Button | 
					
						
							|  |  |  |         block={ true } | 
					
						
							|  |  |  |         bsSize='small' | 
					
						
							|  |  |  |         bsStyle='primary' | 
					
						
							|  |  |  |         className='animated fadeIn' | 
					
						
							|  |  |  |         onClick={ submitChallenge } | 
					
						
							| 
									
										
										
										
											2016-06-14 18:47:43 -07:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  |         Submit and go to my next challenge | 
					
						
							|  |  |  |       </Button> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2016-06-27 20:11:52 -07:00
										 |  |  |     const { router } = this.context; | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |     const { | 
					
						
							|  |  |  |       username, | 
					
						
							|  |  |  |       points, | 
					
						
							|  |  |  |       picture, | 
					
						
							|  |  |  |       updateNavHeight, | 
					
						
							|  |  |  |       isMapDrawerOpen, | 
					
						
							|  |  |  |       isMapAlreadyLoaded, | 
					
						
							| 
									
										
										
										
											2016-06-03 23:34:28 -07:00
										 |  |  |       toggleMapDrawer, | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |       toggleMainChat, | 
					
						
							| 
									
										
										
										
											2016-06-27 20:11:52 -07:00
										 |  |  |       shouldShowSignIn, | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  |       params: { lang }, | 
					
						
							| 
									
										
										
										
											2016-08-03 12:56:00 -07:00
										 |  |  |       trackEvent, | 
					
						
							|  |  |  |       loadCurrentChallenge | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |     } = this.props; | 
					
						
							|  |  |  |     const navProps = { | 
					
						
							| 
									
										
										
										
											2016-06-27 20:11:52 -07:00
										 |  |  |       isOnMap: router.isActive(`/${lang}/map`), | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |       username, | 
					
						
							|  |  |  |       points, | 
					
						
							|  |  |  |       picture, | 
					
						
							|  |  |  |       updateNavHeight, | 
					
						
							| 
									
										
										
										
											2016-06-03 23:34:28 -07:00
										 |  |  |       toggleMapDrawer, | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |       toggleMainChat, | 
					
						
							| 
									
										
										
										
											2016-07-21 16:35:37 -07:00
										 |  |  |       shouldShowSignIn, | 
					
						
							| 
									
										
										
										
											2016-08-03 12:56:00 -07:00
										 |  |  |       trackEvent, | 
					
						
							|  |  |  |       loadCurrentChallenge | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |       <div> | 
					
						
							|  |  |  |         <Nav { ...navProps }/> | 
					
						
							|  |  |  |         <Row> | 
					
						
							|  |  |  |           { this.props.children } | 
					
						
							|  |  |  |         </Row> | 
					
						
							| 
									
										
										
										
											2016-06-03 13:43:42 -07:00
										 |  |  |         <MapDrawer | 
					
						
							|  |  |  |           isAlreadyLoaded={ isMapAlreadyLoaded } | 
					
						
							|  |  |  |           isOpen={ isMapDrawerOpen } | 
					
						
							|  |  |  |           toggleMapDrawer={ toggleMapDrawer } | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2016-07-06 11:47:16 -07:00
										 |  |  |         <Toasts /> | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  | export default connect( | 
					
						
							|  |  |  |   mapStateToProps, | 
					
						
							|  |  |  |   bindableActions | 
					
						
							|  |  |  | )(FreeCodeCamp); |