2015-06-17 21:04:28 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
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,
|
2016-07-21 16:35:37 -07:00
|
|
|
updateAppLang,
|
2015-06-17 21:04:28 -07:00
|
|
|
|
2017-07-31 20:04:01 -07:00
|
|
|
userSelector
|
|
|
|
} from './redux';
|
2016-06-01 15:52:08 -07:00
|
|
|
|
2017-07-31 20:04:01 -07:00
|
|
|
import Nav from './Nav';
|
|
|
|
import Toasts from './Toasts';
|
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,
|
2016-07-20 15:06:44 -07:00
|
|
|
fetchUser,
|
2017-03-13 16:17:07 -07:00
|
|
|
updateAppLang
|
2016-07-20 15:06:44 -07:00
|
|
|
};
|
|
|
|
|
2017-07-31 20:04:01 -07:00
|
|
|
const mapStateToProps = state => {
|
|
|
|
const { username } = userSelector(state);
|
|
|
|
return {
|
|
|
|
toast: state.app.toast,
|
2017-05-03 19:22:05 -05:00
|
|
|
isSignedIn: !!username
|
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,
|
2017-01-12 06:54:43 +00:00
|
|
|
fetchUser: PropTypes.func,
|
2016-10-28 22:14:39 -07:00
|
|
|
isSignedIn: PropTypes.bool,
|
2017-01-12 06:54:43 +00:00
|
|
|
params: PropTypes.object,
|
|
|
|
toast: PropTypes.object,
|
2017-07-31 20:04:01 -07:00
|
|
|
updateAppLang: PropTypes.func.isRequired
|
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-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() {
|
2017-07-31 20:04:01 -07:00
|
|
|
this.props.appMounted();
|
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-07-31 20:04:01 -07:00
|
|
|
// we render nav after the content
|
|
|
|
// to allow the panes to update
|
|
|
|
// redux store, which will update the bin
|
|
|
|
// buttons in the nav
|
2016-01-27 11:34:44 -08:00
|
|
|
return (
|
2017-03-13 16:17:07 -07:00
|
|
|
<div className={ `${ns}-container` }>
|
2017-07-31 20:04:01 -07:00
|
|
|
{ this.props.children }
|
|
|
|
<Nav />
|
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);
|