freeCodeCamp/common/app/App.jsx

82 lines
1.8 KiB
JavaScript
Raw Normal View History

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);
export default contain(
{
2016-01-07 22:51:41 +00:00
actions: ['appActions'],
store: 'appStore',
fetchAction: 'appActions.getUser',
isPrimed({ username }) {
return !!username;
},
2016-01-07 22:51:41 +00:00
map({
username,
points,
picture,
toast
}) {
return {
username,
points,
picture,
toast
};
},
getPayload(props) {
return {
isPrimed: !!props.username
};
}
},
React.createClass({
displayName: 'FreeCodeCamp',
2015-06-18 04:04:28 +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,
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
}
);
}
},
render() {
2015-07-25 04:54:19 +00:00
const { username, points, picture } = this.props;
const navProps = { username, points, picture };
return (
<div>
2015-07-25 04:54:19 +00:00
<Nav
{ ...navProps }/>
<Row>
{ this.props.children }
</Row>
2016-01-07 22:51:41 +00:00
<ToastContainer
className='toast-bottom-right'
ref='toaster'
toastMessageFactory={ toastMessageFactory } />
</div>
);
}
})
);