2017-07-08 07:06:02 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-10-08 09:55:58 +09:00
|
|
|
import { Switch, Route } from 'react-router-dom';
|
2017-07-08 07:06:02 +09:00
|
|
|
|
|
|
|
import ColumnLoading from '../components/column_loading';
|
|
|
|
import BundleColumnError from '../components/bundle_column_error';
|
|
|
|
import BundleContainer from '../containers/bundle_container';
|
|
|
|
|
|
|
|
// Small wrapper to pass multiColumn to the route components
|
2017-11-01 20:17:53 +09:00
|
|
|
export class WrappedSwitch extends React.PureComponent {
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { multiColumn, children } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Switch>
|
|
|
|
{React.Children.map(children, child => React.cloneElement(child, { multiColumn }))}
|
|
|
|
</Switch>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-07-08 07:06:02 +09:00
|
|
|
|
|
|
|
WrappedSwitch.propTypes = {
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
2018-09-14 07:53:09 +09:00
|
|
|
// Small Wrapper to extract the params from the route and pass
|
2017-07-08 07:06:02 +09:00
|
|
|
// them to the rendered component, together with the content to
|
|
|
|
// be rendered inside (the children)
|
|
|
|
export class WrappedRoute extends React.Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
component: PropTypes.func.isRequired,
|
|
|
|
content: PropTypes.node,
|
|
|
|
multiColumn: PropTypes.bool,
|
2018-03-01 10:48:44 +09:00
|
|
|
componentParams: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
componentParams: {},
|
|
|
|
};
|
2017-07-08 07:06:02 +09:00
|
|
|
|
|
|
|
renderComponent = ({ match }) => {
|
2018-03-01 10:48:44 +09:00
|
|
|
const { component, content, multiColumn, componentParams } = this.props;
|
2017-07-08 07:06:02 +09:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BundleContainer fetchComponent={component} loading={this.renderLoading} error={this.renderError}>
|
2018-03-01 10:48:44 +09:00
|
|
|
{Component => <Component params={match.params} multiColumn={multiColumn} {...componentParams}>{content}</Component>}
|
2017-07-08 07:06:02 +09:00
|
|
|
</BundleContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLoading = () => {
|
|
|
|
return <ColumnLoading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderError = (props) => {
|
|
|
|
return <BundleColumnError {...props} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { component: Component, content, ...rest } = this.props;
|
|
|
|
|
|
|
|
return <Route {...rest} render={this.renderComponent} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|