From 45c44989c8fb6e24badd18bb83ac5f68de0aceaf Mon Sep 17 00:00:00 2001 From: kibigo! Date: Fri, 17 Nov 2017 19:11:18 -0800 Subject: Forking glitch theme --- .../themes/glitch/util/react_router_helpers.js | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 app/javascript/themes/glitch/util/react_router_helpers.js (limited to 'app/javascript/themes/glitch/util/react_router_helpers.js') diff --git a/app/javascript/themes/glitch/util/react_router_helpers.js b/app/javascript/themes/glitch/util/react_router_helpers.js new file mode 100644 index 000000000..c02fb5247 --- /dev/null +++ b/app/javascript/themes/glitch/util/react_router_helpers.js @@ -0,0 +1,64 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Switch, Route } from 'react-router-dom'; + +import ColumnLoading from 'themes/glitch/features/ui/components/column_loading'; +import BundleColumnError from 'themes/glitch/features/ui/components/bundle_column_error'; +import BundleContainer from 'themes/glitch/features/ui/containers/bundle_container'; + +// Small wrapper to pass multiColumn to the route components +export class WrappedSwitch extends React.PureComponent { + + render () { + const { multiColumn, children } = this.props; + + return ( + + {React.Children.map(children, child => React.cloneElement(child, { multiColumn }))} + + ); + } + +} + +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 }) => { + const { component, content, multiColumn } = this.props; + + return ( + + {Component => {content}} + + ); + } + + renderLoading = () => { + return ; + } + + renderError = (props) => { + return ; + } + + render () { + const { component: Component, content, ...rest } = this.props; + + return ; + } + +} -- cgit