2015-06-18 04:04:28 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-01-27 19:34:44 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2017-03-13 23:17:07 +00:00
|
|
|
import ns from './ns.json';
|
2016-03-06 05:06:04 +00:00
|
|
|
import {
|
2017-08-01 03:04:01 +00:00
|
|
|
appMounted,
|
2016-03-06 05:06:04 +00:00
|
|
|
fetchUser,
|
2016-07-21 23:35:37 +00:00
|
|
|
updateAppLang,
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2017-08-01 03:04:01 +00:00
|
|
|
userSelector
|
|
|
|
} from './redux';
|
2016-06-01 22:52:08 +00:00
|
|
|
|
2017-08-01 03:04:01 +00:00
|
|
|
import Nav from './Nav';
|
|
|
|
import Toasts from './Toasts';
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2016-10-29 05:14:39 +00:00
|
|
|
const mapDispatchToProps = {
|
2017-08-01 03:04:01 +00:00
|
|
|
appMounted,
|
2016-07-20 22:06:44 +00:00
|
|
|
fetchUser,
|
2017-03-13 23:17:07 +00:00
|
|
|
updateAppLang
|
2016-07-20 22:06:44 +00:00
|
|
|
};
|
|
|
|
|
2017-08-01 03:04:01 +00:00
|
|
|
const mapStateToProps = state => {
|
|
|
|
const { username } = userSelector(state);
|
|
|
|
return {
|
|
|
|
toast: state.app.toast,
|
2017-05-04 00:22:05 +00:00
|
|
|
isSignedIn: !!username
|
2017-08-01 03:04:01 +00:00
|
|
|
};
|
|
|
|
};
|
2016-01-27 19:34:44 +00:00
|
|
|
|
2016-10-29 05:14:39 +00:00
|
|
|
const propTypes = {
|
2017-08-01 03:04:01 +00:00
|
|
|
appMounted: PropTypes.func.isRequired,
|
2016-10-29 05:14:39 +00:00
|
|
|
children: PropTypes.node,
|
2017-01-12 06:54:43 +00:00
|
|
|
fetchUser: PropTypes.func,
|
2016-10-29 05:14:39 +00:00
|
|
|
isSignedIn: PropTypes.bool,
|
2017-01-12 06:54:43 +00:00
|
|
|
params: PropTypes.object,
|
|
|
|
toast: PropTypes.object,
|
2017-08-01 03:04:01 +00:00
|
|
|
updateAppLang: PropTypes.func.isRequired
|
2016-10-29 05:14:39 +00:00
|
|
|
};
|
|
|
|
|
2016-01-27 19:34:44 +00:00
|
|
|
// export plain class for testing
|
|
|
|
export class FreeCodeCamp extends React.Component {
|
2016-07-20 22:06:44 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (this.props.params.lang !== nextProps.params.lang) {
|
|
|
|
this.props.updateAppLang(nextProps.params.lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 05:06:04 +00:00
|
|
|
componentDidMount() {
|
2017-08-01 03:04:01 +00:00
|
|
|
this.props.appMounted();
|
2016-06-20 18:35:19 +00:00
|
|
|
if (!this.props.isSignedIn) {
|
|
|
|
this.props.fetchUser();
|
|
|
|
}
|
2016-03-06 05:06:04 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 19:34:44 +00:00
|
|
|
render() {
|
2017-08-01 03:04:01 +00: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 19:34:44 +00:00
|
|
|
return (
|
2017-03-13 23:17:07 +00:00
|
|
|
<div className={ `${ns}-container` }>
|
2017-08-01 03:04:01 +00:00
|
|
|
{ this.props.children }
|
|
|
|
<Nav />
|
2016-07-06 18:47:16 +00:00
|
|
|
<Toasts />
|
2016-01-27 19:34:44 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 01:35:17 +00:00
|
|
|
FreeCodeCamp.displayName = 'freeCodeCamp';
|
2016-10-29 05:14:39 +00:00
|
|
|
FreeCodeCamp.propTypes = propTypes;
|
|
|
|
|
2016-06-20 18:35:19 +00:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
2016-10-29 05:14:39 +00:00
|
|
|
mapDispatchToProps
|
2016-06-20 18:35:19 +00:00
|
|
|
)(FreeCodeCamp);
|