Skip to content

Commit

Permalink
Extract RouteWithLayout and Database.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanveloso committed Apr 22, 2018
1 parent 0380458 commit 89c15d0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
13 changes: 13 additions & 0 deletions frontend/src/components/Common/RouteWithLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { Route } from 'react-router-dom';

const RouteWithLayout = ({ layout, component, ...rest }) => (
<Route
{...rest}
render={props =>
React.createElement(layout, props, React.createElement(component, props))
}
/>
);

export default RouteWithLayout;
1 change: 1 addition & 0 deletions frontend/src/components/Common/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Footer } from './Footer';
export { default as Helmet } from './Helmet';
export { default as RouteWithLayout } from './RouteWithLayout';
28 changes: 26 additions & 2 deletions frontend/src/scenes/Database/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
export { default as Items } from './Items';
export { default as Item } from './Item';
import React from 'react';
import { Switch } from 'react-router-dom';

import { Dashboard } from 'layouts';
import { RouteWithLayout } from 'components/Common';

import Item from './Item';
import Items from './Items';

const Database = () => (
<Switch>
<RouteWithLayout
layout={Dashboard}
component={Items}
exact
path="/database/items"
/>
<RouteWithLayout
layout={Dashboard}
component={Item}
path="/database/item/:id"
/>
</Switch>
);

export default Database;
29 changes: 2 additions & 27 deletions frontend/src/scenes/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,12 @@ import { ConnectedRouter } from 'react-router-redux';
import { ThemeProvider } from 'styled-components';

import App from 'scenes/App';
import { Helmet } from 'components/Common';
import { Item, Items } from 'scenes/Database';
import Database from 'scenes/Database';
import { Helmet, RouteWithLayout } from 'components/Common';
import { Dashboard } from 'layouts';
import { foundation } from 'helpers/foundation';
import { history } from 'store';

const RouteWithLayout = ({ layout, component, ...rest }) => (
<Route
{...rest}
render={props =>
React.createElement(layout, props, React.createElement(component, props))
}
/>
);

const Database = () => (
<Switch>
<RouteWithLayout
layout={Dashboard}
component={Items}
exact
path="/database/items"
/>
<RouteWithLayout
layout={Dashboard}
component={Item}
path="/database/item/:id"
/>
</Switch>
);

const Main = () => (
<Fragment>
<Helmet />
Expand Down

0 comments on commit 89c15d0

Please sign in to comment.