mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Implement ProxyRoute
This commit is contained in:
parent
c174b8b56c
commit
97fd639c30
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import TransactionManager from './ascribe_transaction_manager/transaction_manager';
|
|
||||||
|
|
||||||
import Header from '../components/header';
|
import Header from '../components/header';
|
||||||
import Footer from '../components/footer';
|
import Footer from '../components/footer';
|
||||||
import GlobalNotification from './global_notification';
|
import GlobalNotification from './global_notification';
|
||||||
@ -22,17 +20,14 @@ let AscribeApp = React.createClass({
|
|||||||
let { children, routes } = this.props;
|
let { children, routes } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TransactionManager
|
<div className="container ascribe-default-app">
|
||||||
routes={routes}>
|
<Header routes={routes} />
|
||||||
<div className="container ascribe-default-app">
|
{/* Routes are injected here */}
|
||||||
<Header routes={routes} />
|
{children}
|
||||||
{/* Routes are injected here */}
|
<Footer />
|
||||||
{children}
|
<GlobalNotification />
|
||||||
<Footer />
|
<div id="modal" className="container"></div>
|
||||||
<GlobalNotification />
|
</div>
|
||||||
<div id="modal" className="container"></div>
|
|
||||||
</div>
|
|
||||||
</TransactionManager>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
33
js/components/ascribe_routes/auth_component.js
Normal file
33
js/components/ascribe_routes/auth_component.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import UserStore from '../../stores/user_store';
|
||||||
|
import UserActions from '../../actions/user_actions';
|
||||||
|
|
||||||
|
export function AuthComponent(Component) {
|
||||||
|
return React.createClass({
|
||||||
|
getInitialState() {
|
||||||
|
return UserStore.getState();
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
UserStore.listen(this.onChange);
|
||||||
|
UserActions.fetchCurrentUser();
|
||||||
|
},
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
UserStore.unlisten(this.onChange);
|
||||||
|
},
|
||||||
|
|
||||||
|
onChange(state) {
|
||||||
|
this.setState(state);
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Component {...this.props}/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
41
js/components/ascribe_routes/proxy_route.js
Normal file
41
js/components/ascribe_routes/proxy_route.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import invariant from 'invariant';
|
||||||
|
import { createRoutes } from 'react-router';
|
||||||
|
|
||||||
|
const { string, bool, func, object, oneOfType } = React.PropTypes;
|
||||||
|
|
||||||
|
const ProxyRoute = React.createClass({
|
||||||
|
propTypes: {
|
||||||
|
path: string,
|
||||||
|
ignoreScrollBehavior: bool,
|
||||||
|
handler: oneOfType([ func, string ]),
|
||||||
|
component: oneOfType([ func, string ]),
|
||||||
|
components: oneOfType([ oneOfType([ func, string ]), object ]),
|
||||||
|
getComponents: func,
|
||||||
|
proxyHandler: func
|
||||||
|
},
|
||||||
|
|
||||||
|
statics: {
|
||||||
|
createRouteFromReactElement(element) {
|
||||||
|
element.type.createRouteFromReactElement = false;
|
||||||
|
const [ route ] = createRoutes(element);
|
||||||
|
|
||||||
|
const Component = route.component;
|
||||||
|
const { proxyHandler } = element.props;
|
||||||
|
route.component = proxyHandler(Component);
|
||||||
|
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
invariant(
|
||||||
|
false,
|
||||||
|
'Some error message'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default ProxyRoute;
|
@ -25,6 +25,9 @@ import ErrorNotFoundPage from './components/error_not_found_page';
|
|||||||
|
|
||||||
import RegisterPiece from './components/register_piece';
|
import RegisterPiece from './components/register_piece';
|
||||||
|
|
||||||
|
import ProxyRoute from './components/ascribe_routes/proxy_route';
|
||||||
|
import { AuthComponent } from './components/ascribe_routes/auth_component';
|
||||||
|
|
||||||
import AppConstants from './constants/application_constants';
|
import AppConstants from './constants/application_constants';
|
||||||
|
|
||||||
|
|
||||||
@ -32,8 +35,12 @@ let baseUrl = AppConstants.baseUrl;
|
|||||||
|
|
||||||
const COMMON_ROUTES = (
|
const COMMON_ROUTES = (
|
||||||
<Route path={baseUrl} component={App}>
|
<Route path={baseUrl} component={App}>
|
||||||
|
<ProxyRoute
|
||||||
|
proxyHandler={AuthComponent}
|
||||||
|
path="collection"
|
||||||
|
component={PieceList}
|
||||||
|
headerTitle="COLLECTION"/>
|
||||||
<Route path="register_piece" component={RegisterPiece} headerTitle="+ NEW WORK" />
|
<Route path="register_piece" component={RegisterPiece} headerTitle="+ NEW WORK" />
|
||||||
<Route path="collection" component={PieceList} headerTitle="COLLECTION"/>
|
|
||||||
<Route path="signup" component={SignupContainer} />
|
<Route path="signup" component={SignupContainer} />
|
||||||
<Route path="login" component={LoginContainer} />
|
<Route path="login" component={LoginContainer} />
|
||||||
<Route path="logout" component={LogoutContainer} />
|
<Route path="logout" component={LogoutContainer} />
|
||||||
|
Loading…
Reference in New Issue
Block a user