summaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-01-22 17:19:33 +0100
committerVictor Chabbert <chabbertvi@eisti.eu>2017-01-22 17:19:37 +0100
commit936f7e32781f2d90fa3e3460758005d807fa6120 (patch)
tree1f07ac11edfad755bc30acff9ce605b9c8ff8967 /frontend
parentFix areAllPlayersReady() to understand WAIT action (diff)
downloadseven-wonders-936f7e32781f2d90fa3e3460758005d807fa6120.tar.gz
seven-wonders-936f7e32781f2d90fa3e3460758005d807fa6120.tar.bz2
seven-wonders-936f7e32781f2d90fa3e3460758005d807fa6120.zip
Move saga and router routes in a single file
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/index.js17
-rw-r--r--frontend/src/routes.js31
-rw-r--r--frontend/src/sagas.js17
3 files changed, 37 insertions, 28 deletions
diff --git a/frontend/src/index.js b/frontend/src/index.js
index d5190d53..1959b14a 100644
--- a/frontend/src/index.js
+++ b/frontend/src/index.js
@@ -2,30 +2,19 @@ import 'babel-polyfill'
import React from 'react'
import ReactDOM from 'react-dom'
-import { Router, Route, IndexRoute } from 'react-router'
+import { Router } from 'react-router'
import { Provider } from 'react-redux'
import configureStore from './store'
+import { routes } from './routes'
const initialState = {}
const { store, history } = configureStore(initialState)
import './global-styles.css'
-import HomePage from './containers/home'
-import { LobbyLayout } from './layouts'
-import GameBrowser from './containers/gameBrowser'
-import Error404 from './components/errors/Error404'
ReactDOM.render(
<Provider store={store}>
- <Router history={history}>
- <div className="app">
- <Route path="/" component={LobbyLayout}>
- <IndexRoute component={HomePage} />
- <Route path="/games" component={GameBrowser} />
- </Route>
- <Route path="*" component={Error404} />
- </div>
- </Router>
+ <Router history={history} routes={routes} />
</Provider>,
document.getElementById('root')
);
diff --git a/frontend/src/routes.js b/frontend/src/routes.js
new file mode 100644
index 00000000..25e849de
--- /dev/null
+++ b/frontend/src/routes.js
@@ -0,0 +1,31 @@
+import usernameChoiceSaga from './sagas/usernameChoice'
+import gameBrowserSaga from './sagas/gameBrowser'
+
+export const makeSagaRoutes = wsConnection => ({
+ *'/'() {
+ yield usernameChoiceSaga(wsConnection)
+ },
+ *'/games'() {
+ yield gameBrowserSaga(wsConnection)
+ }
+})
+
+import { LobbyLayout } from './layouts'
+import HomePage from './containers/home'
+import GameBrowser from './containers/gameBrowser'
+import Error404 from './components/errors/Error404'
+
+export const routes = [
+ {
+ path: '/',
+ component: LobbyLayout,
+ indexRoute: { component: HomePage },
+ childRoutes: [
+ { path: '/games', component: GameBrowser }
+ ]
+ },
+ {
+ path: '*',
+ component: Error404,
+ }
+]
diff --git a/frontend/src/sagas.js b/frontend/src/sagas.js
index 7c356e1d..df49b099 100644
--- a/frontend/src/sagas.js
+++ b/frontend/src/sagas.js
@@ -1,22 +1,11 @@
import { router } from 'redux-saga-router'
import { call } from 'redux-saga/effects'
+import { makeSagaRoutes } from './routes'
import createWsConnection from './utils/createWebSocketConnection'
-import usernameChoiceSaga from './sagas/usernameChoice'
-import gameBrowserSaga from './sagas/gameBrowser'
-
-let wsConnection
-const routes = {
- *'/'() {
- yield usernameChoiceSaga(wsConnection)
- },
- *'/games'() {
- yield gameBrowserSaga(wsConnection)
- }
-}
-
export default function *rootSaga(history) {
+ let wsConnection
try {
wsConnection = yield call(createWsConnection)
} catch (error) {
@@ -24,5 +13,5 @@ export default function *rootSaga(history) {
return
}
- yield* router(history, routes)
+ yield* router(history, makeSagaRoutes(wsConnection))
}
bgstack15