The code powering m.abunchtell.com https://m.abunchtell.com
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

65 satır
1.7 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Switch, Route } from 'react-router-dom';
  4. import ColumnLoading from '../components/column_loading';
  5. import BundleColumnError from '../components/bundle_column_error';
  6. import BundleContainer from '../containers/bundle_container';
  7. // Small wrapper to pass multiColumn to the route components
  8. export class WrappedSwitch extends React.PureComponent {
  9. render () {
  10. const { multiColumn, children } = this.props;
  11. return (
  12. <Switch>
  13. {React.Children.map(children, child => React.cloneElement(child, { multiColumn }))}
  14. </Switch>
  15. );
  16. }
  17. }
  18. WrappedSwitch.propTypes = {
  19. multiColumn: PropTypes.bool,
  20. children: PropTypes.node,
  21. };
  22. // Small Wraper to extract the params from the route and pass
  23. // them to the rendered component, together with the content to
  24. // be rendered inside (the children)
  25. export class WrappedRoute extends React.Component {
  26. static propTypes = {
  27. component: PropTypes.func.isRequired,
  28. content: PropTypes.node,
  29. multiColumn: PropTypes.bool,
  30. }
  31. renderComponent = ({ match }) => {
  32. const { component, content, multiColumn } = this.props;
  33. return (
  34. <BundleContainer fetchComponent={component} loading={this.renderLoading} error={this.renderError}>
  35. {Component => <Component params={match.params} multiColumn={multiColumn}>{content}</Component>}
  36. </BundleContainer>
  37. );
  38. }
  39. renderLoading = () => {
  40. return <ColumnLoading />;
  41. }
  42. renderError = (props) => {
  43. return <BundleColumnError {...props} />;
  44. }
  45. render () {
  46. const { component: Component, content, ...rest } = this.props;
  47. return <Route {...rest} render={this.renderComponent} />;
  48. }
  49. }