summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontend/src/containers/App/actions.js5
-rw-r--r--frontend/src/containers/App/constants.js1
-rw-r--r--frontend/src/containers/App/saga.js28
-rw-r--r--frontend/src/containers/GameBrowser/actions.js16
-rw-r--r--frontend/src/containers/GameBrowser/constants.js3
-rw-r--r--frontend/src/containers/GameBrowser/reducer.js13
-rw-r--r--frontend/src/containers/HomePage/actions.js6
-rw-r--r--frontend/src/containers/UserRepo/actions.js8
-rw-r--r--frontend/src/containers/app.js (renamed from frontend/src/containers/App/index.js)2
-rw-r--r--frontend/src/containers/gameBrowser.js (renamed from frontend/src/containers/GameBrowser/index.js)0
-rw-r--r--frontend/src/containers/home.js (renamed from frontend/src/containers/HomePage/index.js)4
-rw-r--r--frontend/src/index.js2
-rw-r--r--frontend/src/reducers.js4
-rw-r--r--frontend/src/redux/game.js27
-rw-r--r--frontend/src/redux/user.js (renamed from frontend/src/containers/UserRepo/reducer.js)15
-rw-r--r--frontend/src/sagas.js2
-rw-r--r--frontend/src/sagas/home.js (renamed from frontend/src/containers/HomePage/saga.js)0
-rw-r--r--frontend/src/sagas/lobby.js (renamed from frontend/src/containers/GameBrowser/saga.js)17
18 files changed, 55 insertions, 98 deletions
diff --git a/frontend/src/containers/App/actions.js b/frontend/src/containers/App/actions.js
deleted file mode 100644
index cfb617d5..00000000
--- a/frontend/src/containers/App/actions.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import { INITIALIZE_WS } from "./constants"
-
-export const initializeWs = () => ({
- type: INITIALIZE_WS
-})
diff --git a/frontend/src/containers/App/constants.js b/frontend/src/containers/App/constants.js
deleted file mode 100644
index be31f8cc..00000000
--- a/frontend/src/containers/App/constants.js
+++ /dev/null
@@ -1 +0,0 @@
-export const INITIALIZE_WS = 'app/INITIALIZE_WS'
diff --git a/frontend/src/containers/App/saga.js b/frontend/src/containers/App/saga.js
deleted file mode 100644
index 0c212142..00000000
--- a/frontend/src/containers/App/saga.js
+++ /dev/null
@@ -1,28 +0,0 @@
-import { put, take } from 'redux-saga/effects'
-import { eventChannel } from 'redux-saga'
-
-function createSocketChannel(socket) {
- return eventChannel(emit => {
- const errorHandler = event => emit(JSON.parse(event.body))
-
- const userErrors = socket.subscribe('/user/queue/errors', errorHandler)
-
- const unsubscribe = () => {
- userErrors.unsubscribe()
- }
-
- return unsubscribe
- })
-}
-
-export function* watchOnErrors(socketConnection) {
- const { socket } = socketConnection
- const socketChannel = createSocketChannel(socket)
-
- while (true) {
- const payload = yield take(socketChannel)
- yield put({ type: 'USER_ERROR', payload })
- }
-}
-
-export default watchOnErrors
diff --git a/frontend/src/containers/GameBrowser/actions.js b/frontend/src/containers/GameBrowser/actions.js
deleted file mode 100644
index 376973b4..00000000
--- a/frontend/src/containers/GameBrowser/actions.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import { NEW_GAME, JOIN_GAME, CREATE_GAME } from './constants'
-
-export const newGame = (game) => ({
- type: NEW_GAME,
- game
-})
-
-export const joinGame = (id) => ({
- type: JOIN_GAME,
- id
-})
-
-export const createGame = (name) => ({
- type: CREATE_GAME,
- name
-})
diff --git a/frontend/src/containers/GameBrowser/constants.js b/frontend/src/containers/GameBrowser/constants.js
deleted file mode 100644
index 36f701b7..00000000
--- a/frontend/src/containers/GameBrowser/constants.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export const NEW_GAME = 'gameBrowser/NEW_GAME'
-export const JOIN_GAME = 'gameBrowser/JOIN_GAME'
-export const CREATE_GAME = 'gameBrowser/CREATE_GAME'
diff --git a/frontend/src/containers/GameBrowser/reducer.js b/frontend/src/containers/GameBrowser/reducer.js
deleted file mode 100644
index 4fb3390a..00000000
--- a/frontend/src/containers/GameBrowser/reducer.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { Map } from 'immutable'
-import { NEW_GAME } from './constants'
-
-const initialState = Map({})
-
-export default function reducer(state = initialState, action) {
- switch (action.type) {
- case NEW_GAME:
- return state.set(action.game.get('id'), action.game)
- default:
- return state
- }
-}
diff --git a/frontend/src/containers/HomePage/actions.js b/frontend/src/containers/HomePage/actions.js
deleted file mode 100644
index e06d6fa2..00000000
--- a/frontend/src/containers/HomePage/actions.js
+++ /dev/null
@@ -1,6 +0,0 @@
-export const ENTER_GAME = 'homePage/ENTER_GAME'
-
-export const enterGame = (username) => ({
- type: ENTER_GAME,
- username
-})
diff --git a/frontend/src/containers/UserRepo/actions.js b/frontend/src/containers/UserRepo/actions.js
deleted file mode 100644
index dc06035b..00000000
--- a/frontend/src/containers/UserRepo/actions.js
+++ /dev/null
@@ -1,8 +0,0 @@
-export const SET_USERNAME = 'homePage/SET_USERNAME'
-
-export const setUsername = (userName, displayName, index) => ({
- type: SET_USERNAME,
- userName,
- index,
- displayName
-})
diff --git a/frontend/src/containers/App/index.js b/frontend/src/containers/app.js
index 70f99b6b..d2245152 100644
--- a/frontend/src/containers/App/index.js
+++ b/frontend/src/containers/app.js
@@ -10,7 +10,7 @@ import {
} from 'rebass'
import { Flex } from 'reflexbox'
import Modal from '../../components/modals/username'
-import GameBrowser from '../GameBrowser'
+import GameBrowser from './gameBrowser'
class App extends Component {
state = {
diff --git a/frontend/src/containers/GameBrowser/index.js b/frontend/src/containers/gameBrowser.js
index 9deb720b..9deb720b 100644
--- a/frontend/src/containers/GameBrowser/index.js
+++ b/frontend/src/containers/gameBrowser.js
diff --git a/frontend/src/containers/HomePage/index.js b/frontend/src/containers/home.js
index a00f46ae..ce1b69fd 100644
--- a/frontend/src/containers/HomePage/index.js
+++ b/frontend/src/containers/home.js
@@ -32,9 +32,9 @@ const mapStateToProps = (state) => ({
})
-import { enterGame } from './actions'
+import { actions } from '../redux/game'
const mapDispatchToProps = {
- enterGame
+ enterGame: actions.enterGame
}
export default connect(mapStateToProps, mapDispatchToProps)(HomePage)
diff --git a/frontend/src/index.js b/frontend/src/index.js
index 3edce222..7622cd52 100644
--- a/frontend/src/index.js
+++ b/frontend/src/index.js
@@ -10,7 +10,7 @@ const initialState = {}
const { store, history } = configureStore(initialState)
import './global-styles.css'
-import HomePage from './containers/HomePage'
+import HomePage from './containers/home'
import Error404 from './components/errors/Error404'
ReactDOM.render(
diff --git a/frontend/src/reducers.js b/frontend/src/reducers.js
index d9db899b..5cc01ec9 100644
--- a/frontend/src/reducers.js
+++ b/frontend/src/reducers.js
@@ -1,8 +1,8 @@
import { combineReducers } from 'redux'
import { routerReducer } from 'react-router-redux'
-import gamesReducer from './containers/GameBrowser/reducer'
-import userReducer from './containers/UserRepo/reducer'
+import gamesReducer from './redux/game'
+import userReducer from './redux/user'
export default function createReducer() {
return combineReducers({
diff --git a/frontend/src/redux/game.js b/frontend/src/redux/game.js
new file mode 100644
index 00000000..64373958
--- /dev/null
+++ b/frontend/src/redux/game.js
@@ -0,0 +1,27 @@
+import { Map } from 'immutable'
+
+export const types = {
+ NEW_GAME: 'GAME/NEW_GAME',
+ ENTER_GAME: 'GAME/ENTER_GAME',
+ JOIN_GAME: 'GAME/JOIN_GAME',
+ CREATE_GAME: 'GAME/CREATE_GAME',
+}
+
+export const actions = {
+ newGame: (game) => ({ type: types.NEW_GAME, game }),
+ enterGame: (username) => ({ type: types.ENTER_GAME, username }),
+ joinGame: (id) => ({ type: types.JOIN_GAME, id }),
+ createGame: (name) => ({ type: types.CREATE_GAME, name }),
+}
+
+
+const initialState = Map({})
+
+export default (state = initialState, action) => {
+ switch (action.type) {
+ case types.NEW_GAME:
+ return state.set(action.game.get('id'), action.game)
+ default:
+ return state
+ }
+}
diff --git a/frontend/src/containers/UserRepo/reducer.js b/frontend/src/redux/user.js
index 82960a58..0279b49c 100644
--- a/frontend/src/containers/UserRepo/reducer.js
+++ b/frontend/src/redux/user.js
@@ -1,5 +1,16 @@
-import { SET_USERNAME } from './actions'
import { fromJS } from 'immutable'
+
+export const types = {
+ SET_USERNAME: 'USER/SET_USERNAME',
+}
+
+export const setUsername = (userName, displayName, index) => ({
+ type: types.SET_USERNAME,
+ userName,
+ index,
+ displayName
+})
+
const initialState = fromJS({
username: '',
displayName: '',
@@ -8,7 +19,7 @@ const initialState = fromJS({
export default (state = initialState, action) => {
switch (action.type) {
- case SET_USERNAME:
+ case types.SET_USERNAME:
return state.set('username', action.userName)
.set('displayName', action.displayName)
.set('id', action.index)
diff --git a/frontend/src/sagas.js b/frontend/src/sagas.js
index fc2c839f..ab590a0d 100644
--- a/frontend/src/sagas.js
+++ b/frontend/src/sagas.js
@@ -3,7 +3,7 @@ import { call } from 'redux-saga/effects'
import createWsConnection from './utils/createWebSocketConnection'
-import homeSaga from './containers/HomePage/saga'
+import homeSaga from './sagas/home'
let wsConnection
const routes = {
diff --git a/frontend/src/containers/HomePage/saga.js b/frontend/src/sagas/home.js
index 24f385c9..24f385c9 100644
--- a/frontend/src/containers/HomePage/saga.js
+++ b/frontend/src/sagas/home.js
diff --git a/frontend/src/containers/GameBrowser/saga.js b/frontend/src/sagas/lobby.js
index 4cd3d207..144d523a 100644
--- a/frontend/src/containers/GameBrowser/saga.js
+++ b/frontend/src/sagas/lobby.js
@@ -3,8 +3,7 @@ import { eventChannel } from 'redux-saga'
import { fromJS } from 'immutable'
import { push } from 'react-router-redux'
-import { NEW_GAME, JOIN_GAME, CREATE_GAME } from './constants'
-import { newGame, joinGame } from './actions'
+import { actions, types } from '../../redux/game'
function createSocketChannel(socket) {
return eventChannel(emit => {
@@ -17,8 +16,8 @@ function createSocketChannel(socket) {
})
}
- const newGameHandler = makeHandler(NEW_GAME)
- const joinGameHandler = makeHandler(JOIN_GAME)
+ const newGameHandler = makeHandler(types.NEW_GAME)
+ const joinGameHandler = makeHandler(types.JOIN_GAME)
const newGame = socket.subscribe('/topic/games', newGameHandler)
const joinGame = socket.subscribe('/user/queue/join-game', joinGameHandler)
@@ -41,11 +40,11 @@ export function* watchGames(socketConnection) {
const { type, response } = yield take(socketChannel)
switch (type) {
- case NEW_GAME:
- yield put(newGame(response))
+ case types.NEW_GAME:
+ yield put(actions.newGame(response))
break;
- case JOIN_GAME:
- yield put(joinGame(response))
+ case types.JOIN_GAME:
+ yield put(actions.joinGame(response))
break;
default:
console.error('Unknown type')
@@ -54,7 +53,7 @@ export function* watchGames(socketConnection) {
}
export function* createGame(socketConnection) {
- const { name } = yield take(CREATE_GAME)
+ const { name } = yield take(types.CREATE_GAME)
const { socket } = socketConnection
socket.send("/app/lobby/create-game", JSON.stringify({
bgstack15