2016-02-27 21:53:11 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { render } from 'react-dom';
|
|
|
|
import { Provider } from 'react-redux';
|
2016-05-07 16:18:20 +00:00
|
|
|
import Router from 'react-router/lib/Router';
|
|
|
|
import Route from 'react-router/lib/Route';
|
|
|
|
import IndexRoute from 'react-router/lib/IndexRoute';
|
2016-03-05 22:27:29 +00:00
|
|
|
import { createStore, applyMiddleware } from 'redux';
|
2016-04-29 05:25:37 +00:00
|
|
|
import { routerMiddleware } from 'react-router-redux';
|
|
|
|
import { persistStore, autoRehydrate } from 'redux-persist';
|
|
|
|
import thunkMiddleware from 'redux-thunk';
|
|
|
|
import createLogger from 'redux-logger';
|
|
|
|
import History from 'utils/History';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2016-04-29 05:25:37 +00:00
|
|
|
import auth from 'utils/auth';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2016-04-29 05:25:37 +00:00
|
|
|
import reducers from 'reducers';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2016-05-04 06:43:43 +00:00
|
|
|
import 'normalize.css/normalize.css';
|
2016-04-29 05:25:37 +00:00
|
|
|
import 'utils/base-styles.scss';
|
2016-05-04 06:43:43 +00:00
|
|
|
import 'fonts/atlas/atlas.css';
|
2016-04-29 05:25:37 +00:00
|
|
|
|
|
|
|
import Home from 'scenes/Home';
|
2016-05-03 07:32:40 +00:00
|
|
|
// import App from 'scenes/App';
|
2016-04-29 05:25:37 +00:00
|
|
|
import Dashboard from 'scenes/Dashboard';
|
|
|
|
import SlackAuth from 'scenes/SlackAuth';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2016-02-29 06:15:25 +00:00
|
|
|
// Redux
|
|
|
|
|
2016-04-29 05:25:37 +00:00
|
|
|
const loggerMiddleware = createLogger();
|
|
|
|
const routerMiddlewareWithHistory = routerMiddleware(History);
|
2016-02-29 03:02:39 +00:00
|
|
|
|
2016-05-03 07:32:40 +00:00
|
|
|
const store = createStore(reducers, applyMiddleware(
|
2016-04-29 05:25:37 +00:00
|
|
|
thunkMiddleware,
|
|
|
|
routerMiddlewareWithHistory,
|
|
|
|
loggerMiddleware,
|
|
|
|
), autoRehydrate());
|
2016-05-03 04:58:39 +00:00
|
|
|
|
|
|
|
persistStore(store, {
|
|
|
|
whitelist: [
|
|
|
|
'user',
|
|
|
|
'team',
|
|
|
|
]
|
|
|
|
}, () => {
|
|
|
|
render((
|
|
|
|
<Provider store={store}>
|
|
|
|
<Router history={History}>
|
|
|
|
<Route path="/">
|
|
|
|
<IndexRoute component={Home} />
|
|
|
|
|
|
|
|
<Route path="/dashboard" component={Dashboard
|
|
|
|
} onEnter={ requireAuth } />
|
|
|
|
<Route path="/atlas/:id" component={Dashboard} onEnter={ requireAuth } />
|
|
|
|
<Route path="/atlas/:id/new" component={Dashboard} onEnter={ requireAuth } />
|
|
|
|
|
|
|
|
<Route path="/editor" component={Dashboard} />
|
|
|
|
|
|
|
|
<Route path="/auth/slack" component={SlackAuth} />
|
|
|
|
</Route>
|
|
|
|
</Router>
|
|
|
|
</Provider>
|
|
|
|
), document.getElementById('root'));
|
|
|
|
});
|
2016-02-29 06:15:25 +00:00
|
|
|
|
2016-02-27 21:53:11 +00:00
|
|
|
function requireAuth(nextState, replace) {
|
2016-04-29 05:25:37 +00:00
|
|
|
if (!auth.loggedIn()) {
|
2016-02-27 21:53:11 +00:00
|
|
|
replace({
|
2016-04-29 05:25:37 +00:00
|
|
|
pathname: '/',
|
2016-02-27 21:53:11 +00:00
|
|
|
state: { nextPathname: nextState.location.pathname },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|