diff options
Diffstat (limited to 'frontend/src/sagas/gameBrowser.js')
-rw-r--r-- | frontend/src/sagas/gameBrowser.js | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/frontend/src/sagas/gameBrowser.js b/frontend/src/sagas/gameBrowser.js index 062603a3..fec83451 100644 --- a/frontend/src/sagas/gameBrowser.js +++ b/frontend/src/sagas/gameBrowser.js @@ -1,24 +1,18 @@ // @flow -import { normalize } from 'normalizr'; import { push } from 'react-router-redux'; import type { SagaIterator } from 'redux-saga'; import { eventChannel } from 'redux-saga'; import { all, apply, call, put, take } from 'redux-saga/effects'; +import type { ApiLobby } from '../api/model'; import type { SevenWondersSession } from '../api/sevenWondersApi'; -import { actions as gameActions } from '../redux/actions/lobby'; -import { types } from '../redux/actions/lobby'; -import { actions as playerActions } from '../redux/actions/players'; -import { game as gameSchema, gameList as gameListSchema } from '../schemas/games'; +import { actions as gameActions, types } from '../redux/actions/lobby'; function* watchGames(session: SevenWondersSession): SagaIterator { const gamesChannel = yield eventChannel(session.watchGames()); try { while (true) { const gameList = yield take(gamesChannel); - const normGameList = normalize(gameList, gameListSchema); - // for an empty game array, there is no players/games entity maps - yield put(playerActions.updatePlayers(normGameList.entities.players || {})); - yield put(gameActions.updateGames(normGameList.entities.games || {})); + yield put(gameActions.updateGames(gameList)); } } finally { yield apply(gamesChannel, gamesChannel.close); @@ -28,13 +22,10 @@ function* watchGames(session: SevenWondersSession): SagaIterator { function* watchLobbyJoined(session: SevenWondersSession): SagaIterator { const joinedLobbyChannel = yield eventChannel(session.watchLobbyJoined()); try { - const joinedLobby = yield take(joinedLobbyChannel); - const normalized = normalize(joinedLobby, gameSchema); - const gameId = normalized.result; - yield put(playerActions.updatePlayers(normalized.entities.players)); - yield put(gameActions.updateGames(normalized.entities.games)); - yield put(gameActions.enterLobby(gameId)); - yield put(push(`/lobby/${gameId}`)); + const joinedLobby: ApiLobby = yield take(joinedLobbyChannel); + yield put(gameActions.updateGames([joinedLobby])); + yield put(gameActions.enterLobby(joinedLobby.id)); + yield put(push(`/lobby/${joinedLobby.id}`)); } finally { yield apply(joinedLobbyChannel, joinedLobbyChannel.close); } |