You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
65 lines
1.8 KiB
7 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
7 years ago
|
import { Switch, Route } from 'react-router-dom';
|
||
7 years ago
|
|
||
7 years ago
|
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';
|
||
7 years ago
|
|
||
|
// Small wrapper to pass multiColumn to the route components
|
||
7 years ago
|
export class WrappedSwitch extends React.PureComponent {
|
||
|
|
||
|
render () {
|
||
|
const { multiColumn, children } = this.props;
|
||
|
|
||
|
return (
|
||
|
<Switch>
|
||
|
{React.Children.map(children, child => React.cloneElement(child, { multiColumn }))}
|
||
|
</Switch>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|
||
7 years ago
|
|
||
|
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 }) => {
|
||
7 years ago
|
const { component, content, multiColumn } = this.props;
|
||
7 years ago
|
|
||
|
return (
|
||
|
<BundleContainer fetchComponent={component} loading={this.renderLoading} error={this.renderError}>
|
||
7 years ago
|
{Component => <Component params={match.params} multiColumn={multiColumn}>{content}</Component>}
|
||
7 years ago
|
</BundleContainer>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
renderLoading = () => {
|
||
|
return <ColumnLoading />;
|
||
|
}
|
||
|
|
||
|
renderError = (props) => {
|
||
|
return <BundleColumnError {...props} />;
|
||
|
}
|
||
|
|
||
|
render () {
|
||
|
const { component: Component, content, ...rest } = this.props;
|
||
|
|
||
|
return <Route {...rest} render={this.renderComponent} />;
|
||
|
}
|
||
|
|
||
|
}
|