| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  | import React from 'react'; | 
					
						
							|  |  |  | import PropTypes from 'prop-types'; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | import { connect } from 'react-redux'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-13 16:17:07 -07:00
										 |  |  | import ns from './ns.json'; | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |   appMounted, | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  |   fetchUser, | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |   isSignedInSelector | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | } from './redux'; | 
					
						
							| 
									
										
										
										
											2016-06-01 15:52:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 06:12:05 +01:00
										 |  |  | import { fetchMapUi } from './Map/redux'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-04 09:18:20 -08:00
										 |  |  | import Flash from './Flash'; | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | import Nav from './Nav'; | 
					
						
							|  |  |  | import Toasts from './Toasts'; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  | import NotFound from './NotFound'; | 
					
						
							|  |  |  | import { mainRouteSelector } from './routes/redux'; | 
					
						
							| 
									
										
										
										
											2018-02-19 20:32:14 +00:00
										 |  |  | import Profile from './routes/Profile'; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  | import Settings from './routes/Settings'; | 
					
						
							| 
									
										
										
										
											2015-06-17 21:04:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  | const mapDispatchToProps = { | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |   appMounted, | 
					
						
							| 
									
										
										
										
											2018-05-15 06:12:05 +01:00
										 |  |  |   fetchMapUi, | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |   fetchUser | 
					
						
							| 
									
										
										
										
											2016-07-20 15:06:44 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  | const mapStateToProps = state => { | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |   const isSignedIn = isSignedInSelector(state); | 
					
						
							|  |  |  |   const route = mainRouteSelector(state); | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |   return { | 
					
						
							|  |  |  |     toast: state.app.toast, | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |     isSignedIn, | 
					
						
							|  |  |  |     route | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  | const propTypes = { | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |   appMounted: PropTypes.func.isRequired, | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  |   children: PropTypes.node, | 
					
						
							| 
									
										
										
										
											2018-05-15 06:12:05 +01:00
										 |  |  |   fetchMapUi: PropTypes.func.isRequired, | 
					
						
							| 
									
										
										
										
											2017-01-12 06:54:43 +00:00
										 |  |  |   fetchUser: PropTypes.func, | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  |   isSignedIn: PropTypes.bool, | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |   route: PropTypes.string, | 
					
						
							|  |  |  |   toast: PropTypes.object | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const routes = { | 
					
						
							| 
									
										
										
										
											2018-02-19 20:32:14 +00:00
										 |  |  |   profile: Profile, | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |   settings: Settings | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  | // export plain class for testing
 | 
					
						
							|  |  |  | export class FreeCodeCamp extends React.Component { | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  |   componentDidMount() { | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |     this.props.appMounted(); | 
					
						
							| 
									
										
										
										
											2018-05-15 06:12:05 +01:00
										 |  |  |     this.props.fetchMapUi(); | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  |     if (!this.props.isSignedIn) { | 
					
						
							|  |  |  |       this.props.fetchUser(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-03-05 21:06:04 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |   render() { | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |     const { | 
					
						
							|  |  |  |       route | 
					
						
							|  |  |  |     } = this.props; | 
					
						
							|  |  |  |     const Child = routes[route] || NotFound; | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |     return ( | 
					
						
							| 
									
										
										
										
											2017-03-13 16:17:07 -07:00
										 |  |  |       <div className={ `${ns}-container` }> | 
					
						
							| 
									
										
										
										
											2018-01-04 09:18:20 -08:00
										 |  |  |         <Flash /> | 
					
						
							| 
									
										
										
										
											2017-07-31 20:04:01 -07:00
										 |  |  |         <Nav /> | 
					
						
							| 
									
										
										
										
											2017-11-09 17:10:30 -08:00
										 |  |  |         <Child /> | 
					
						
							| 
									
										
										
										
											2016-07-06 11:47:16 -07:00
										 |  |  |         <Toasts /> | 
					
						
							| 
									
										
										
										
											2016-01-27 11:34:44 -08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-01 20:35:17 -05:00
										 |  |  | FreeCodeCamp.displayName = 'freeCodeCamp'; | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  | FreeCodeCamp.propTypes = propTypes; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  | export default connect( | 
					
						
							|  |  |  |   mapStateToProps, | 
					
						
							| 
									
										
										
										
											2016-10-28 22:14:39 -07:00
										 |  |  |   mapDispatchToProps | 
					
						
							| 
									
										
										
										
											2016-06-20 11:35:19 -07:00
										 |  |  | )(FreeCodeCamp); |