joyent-portal/frontend/src/containers/app.js

80 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { connect } from 'react-redux';
import { Switch, Route } from 'react-router-dom';
import { injectGlobal } from 'styled-components';
import { updateRouter } from '@state/actions';
import Article from '@components/article';
2017-02-24 14:10:28 +02:00
import Base, { global } from '@ui/components/base';
import BaselineGrid from '@ui/components/baseline-grid';
import Footer from '@components/footer';
import Header from '@containers/header';
import Home from '@containers/home';
import NotFound from '@containers/not-found';
import Nav from '@components/navigation';
import OrgNavigation from '@components/navigation/org';
2016-12-13 16:35:39 +02:00
2016-10-20 04:14:26 +03:00
const App = connect()(React.createClass({
2016-12-14 00:09:04 +02:00
displayName: 'App',
2016-10-25 22:15:33 +03:00
propTypes: {
children: React.PropTypes.node,
dispatch: React.PropTypes.func,
router: React.PropTypes.object
},
2016-10-20 04:14:26 +03:00
componentWillMount: function() {
const {
router,
dispatch
} = this.props;
// ugly hack needed because of a limitation of react-router api
// that doens't pass it's instance to matched routes
2016-10-20 22:42:39 +03:00
// wait for react-router-redux@5
2016-10-20 04:14:26 +03:00
dispatch(updateRouter(router));
2016-12-13 16:35:39 +02:00
injectGlobal`
2017-02-24 14:10:28 +02:00
${global}
2016-12-13 16:35:39 +02:00
`;
2016-10-20 04:14:26 +03:00
},
render: function() {
const {
children
} = this.props;
let _children = children;
if (!Array.isArray(_children)) {
return _children;
}
if (process.env.NODE_ENV !== 'production' && process.env.BASELINE_GRID) {
_children = (
<BaselineGrid>
{_children}
</BaselineGrid>
);
2016-10-20 04:14:26 +03:00
}
return (
2016-12-13 16:35:39 +02:00
<Base>
{_children}
2016-12-13 16:35:39 +02:00
</Base>
2016-10-20 04:14:26 +03:00
);
}
}));
export default (props) => (
2017-02-06 20:27:10 +02:00
<App {...props}>
<Header />
<Nav name='application-org-navigation'>
2017-02-06 20:27:10 +02:00
<OrgNavigation />
</Nav>
<Article name='application-content'>
2017-02-06 20:27:10 +02:00
<Switch>
<Route component={Home} path='/:org?/:section?' />
<Route component={NotFound} />
</Switch>
</Article>
<Footer name='application-footer' />
2017-02-06 20:27:10 +02:00
</App>
);