2015-06-18 04:04:28 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
2015-07-04 15:16:42 +00:00
|
|
|
import { Row } from 'react-bootstrap';
|
2016-01-07 22:51:41 +00:00
|
|
|
import { ToastMessage, ToastContainer } from 'react-toastr';
|
|
|
|
import { contain } from 'thundercats-react';
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2016-01-06 17:33:55 +00:00
|
|
|
import Nav from './components/Nav';
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2016-01-07 22:51:41 +00:00
|
|
|
const toastMessageFactory = React.createFactory(ToastMessage.animation);
|
|
|
|
|
2015-07-25 00:52:07 +00:00
|
|
|
export default contain(
|
|
|
|
{
|
2016-01-07 22:51:41 +00:00
|
|
|
actions: ['appActions'],
|
2015-07-25 00:52:07 +00:00
|
|
|
store: 'appStore',
|
|
|
|
fetchAction: 'appActions.getUser',
|
2016-01-05 20:26:14 +00:00
|
|
|
isPrimed({ username }) {
|
|
|
|
return !!username;
|
|
|
|
},
|
2016-01-07 22:51:41 +00:00
|
|
|
map({
|
|
|
|
username,
|
|
|
|
points,
|
|
|
|
picture,
|
|
|
|
toast
|
|
|
|
}) {
|
|
|
|
return {
|
|
|
|
username,
|
|
|
|
points,
|
|
|
|
picture,
|
|
|
|
toast
|
|
|
|
};
|
|
|
|
},
|
2015-07-25 00:52:07 +00:00
|
|
|
getPayload(props) {
|
|
|
|
return {
|
|
|
|
isPrimed: !!props.username
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
React.createClass({
|
|
|
|
displayName: 'FreeCodeCamp',
|
2015-06-18 04:04:28 +00:00
|
|
|
|
2015-07-25 00:52:07 +00:00
|
|
|
propTypes: {
|
2016-01-07 22:51:41 +00:00
|
|
|
appActions: PropTypes.object,
|
2015-07-25 04:54:19 +00:00
|
|
|
children: PropTypes.node,
|
2016-01-07 22:51:41 +00:00
|
|
|
username: PropTypes.string,
|
2015-07-25 04:54:19 +00:00
|
|
|
points: PropTypes.number,
|
2015-07-29 17:16:48 +00:00
|
|
|
picture: PropTypes.string,
|
2016-01-07 22:51:41 +00:00
|
|
|
toast: PropTypes.object
|
|
|
|
},
|
|
|
|
|
2016-01-10 06:48:48 +00:00
|
|
|
componentWillReceiveProps({ toast: nextToast = {} }) {
|
2016-01-07 22:51:41 +00:00
|
|
|
const { toast = {} } = this.props;
|
2016-01-10 06:48:48 +00:00
|
|
|
if (toast.id !== nextToast.id) {
|
2016-01-07 22:51:41 +00:00
|
|
|
this.refs.toaster[nextToast.type || 'success'](
|
|
|
|
nextToast.message,
|
|
|
|
nextToast.title,
|
|
|
|
{
|
|
|
|
closeButton: true,
|
|
|
|
timeOut: 10000
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2015-07-29 17:16:48 +00:00
|
|
|
},
|
|
|
|
|
2015-07-25 00:52:07 +00:00
|
|
|
render() {
|
2015-07-25 04:54:19 +00:00
|
|
|
const { username, points, picture } = this.props;
|
|
|
|
const navProps = { username, points, picture };
|
2015-07-25 00:52:07 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2015-07-25 04:54:19 +00:00
|
|
|
<Nav
|
|
|
|
{ ...navProps }/>
|
2015-07-25 00:52:07 +00:00
|
|
|
<Row>
|
|
|
|
{ this.props.children }
|
|
|
|
</Row>
|
2016-01-07 22:51:41 +00:00
|
|
|
<ToastContainer
|
|
|
|
className='toast-bottom-right'
|
|
|
|
ref='toaster'
|
|
|
|
toastMessageFactory={ toastMessageFactory } />
|
2015-07-25 00:52:07 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|