1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/app.jsx

78 lines
3.1 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Layout, Header, Navigation, Content, Footer, Grid, Cell } from 'react-mdl';
import { Route, Redirect, Switch } from 'react-router-dom';
import styles from './styles.scss';
2016-11-10 14:26:24 +01:00
import ErrorContainer from './error/error-container';
import AuthenticationContainer from './user/authentication-container';
2016-11-25 15:37:06 +01:00
import ShowUserContainer from './user/show-user-container';
2017-11-24 08:41:36 +01:00
import ShowApiDetailsContainer from './api/show-api-details-container';
import Features from '../page/features';
import { DrawerMenu } from './menu/drawer';
import { FooterMenu } from './menu/footer';
import Breadcrum from './menu/breadcrumb';
import { routes } from './menu/routes';
2016-12-05 17:04:00 +01:00
2016-11-10 14:26:24 +01:00
export default class App extends Component {
static propTypes = {
location: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
};
2016-11-10 14:26:24 +01:00
2016-12-04 11:56:41 +01:00
static contextTypes = {
router: PropTypes.object,
};
2016-11-10 14:26:24 +01:00
componentWillReceiveProps(nextProps) {
2016-12-05 17:10:32 +01:00
if (this.props.location.pathname !== nextProps.location.pathname) {
2016-12-11 19:30:56 +01:00
clearTimeout(this.timer);
this.timer = setTimeout(() => {
const layout = document.querySelector('.mdl-js-layout');
const drawer = document.querySelector('.mdl-layout__drawer');
// hack, might get a built in alternative later
if (drawer.classList.contains('is-visible')) {
layout.MaterialLayout.toggleDrawer();
}
}, 10);
2016-12-05 17:10:32 +01:00
}
}
render() {
2016-12-04 11:56:41 +01:00
return (
2017-03-01 21:53:25 +01:00
<div className={styles.container}>
<AuthenticationContainer />
2016-12-04 11:56:41 +01:00
<Layout fixedHeader>
<Header title={<Route path="/:path" component={Breadcrum} />}>
2016-12-04 11:56:41 +01:00
<Navigation>
<ShowUserContainer />
</Navigation>
</Header>
<DrawerMenu />
<Content className="mdl-color--grey-50">
<Grid noSpacing className={styles.content}>
<Cell col={12}>
<Switch>
<Route
exact
path="/"
render={() => <Redirect to="/features" component={Features} />}
/>
{routes.map(route => (
<Route key={route.path} path={route.path} component={route.component} />
))}
</Switch>
<ErrorContainer />
</Cell>
</Grid>
<Footer size="mega">
<FooterMenu />
<ShowApiDetailsContainer />
</Footer>
</Content>
2016-12-04 11:56:41 +01:00
</Layout>
</div>
);
2016-11-10 14:26:24 +01:00
}
}