2017-07-07 15:06:02 -07:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-10-07 17:55:58 -07:00
|
|
|
import { Switch, Route } from 'react-router-dom';
|
2017-07-07 15:06:02 -07:00
|
|
|
|
2017-12-03 23:26:40 -08:00
|
|
|
import ColumnLoading from 'flavours/glitch/features/ui/components/column_loading';
|
|
|
|
import BundleColumnError from 'flavours/glitch/features/ui/components/bundle_column_error';
|
|
|
|
import BundleContainer from 'flavours/glitch/features/ui/containers/bundle_container';
|
2017-07-07 15:06:02 -07:00
|
|
|
|
|
|
|
// Small wrapper to pass multiColumn to the route components
|
2017-11-01 04:17:53 -07: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-07 15:06:02 -07:00
|
|
|
|
|
|
|
WrappedSwitch.propTypes = {
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Small Wraper to extract the params from the route and pass
|
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
|
|
|
|
renderComponent = ({ match }) => {
|
2017-07-08 09:34:55 -07:00
|
|
|
const { component, content, multiColumn } = this.props;
|
2017-07-07 15:06:02 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BundleContainer fetchComponent={component} loading={this.renderLoading} error={this.renderError}>
|
2017-07-08 09:34:55 -07:00
|
|
|
{Component => <Component params={match.params} multiColumn={multiColumn}>{content}</Component>}
|
2017-07-07 15:06:02 -07:00
|
|
|
</BundleContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLoading = () => {
|
|
|
|
return <ColumnLoading />;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderError = (props) => {
|
|
|
|
return <BundleColumnError {...props} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { component: Component, content, ...rest } = this.props;
|
|
|
|
|
|
|
|
return <Route {...rest} render={this.renderComponent} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|