diff options
-rw-r--r-- | frontend/src/redux/actions/all.js | 5 | ||||
-rw-r--r-- | frontend/src/redux/actions/all.ts | 5 | ||||
-rw-r--r-- | frontend/src/redux/actions/game.js | 34 | ||||
-rw-r--r-- | frontend/src/redux/actions/game.ts | 32 | ||||
-rw-r--r-- | frontend/src/redux/actions/lobby.js | 34 | ||||
-rw-r--r-- | frontend/src/redux/actions/lobby.ts | 32 | ||||
-rw-r--r-- | frontend/src/redux/actions/user.js | 25 | ||||
-rw-r--r-- | frontend/src/redux/actions/user.ts | 17 | ||||
-rw-r--r-- | frontend/src/redux/currentGame.js | 10 | ||||
-rw-r--r-- | frontend/src/redux/games.js | 6 | ||||
-rw-r--r-- | frontend/src/redux/user.js | 4 | ||||
-rw-r--r-- | frontend/src/sagas/game.js | 11 | ||||
-rw-r--r-- | frontend/src/sagas/gameBrowser.js | 6 | ||||
-rw-r--r-- | frontend/src/sagas/home.js | 5 | ||||
-rw-r--r-- | frontend/src/sagas/lobby.js | 6 |
15 files changed, 109 insertions, 123 deletions
diff --git a/frontend/src/redux/actions/all.js b/frontend/src/redux/actions/all.js deleted file mode 100644 index 12522819..00000000 --- a/frontend/src/redux/actions/all.js +++ /dev/null @@ -1,5 +0,0 @@ -import type { GameAction } from './game'; -import type { LobbyAction } from './lobby'; -import type { PlayerAction } from './user'; - -export type Action = PlayerAction | LobbyAction | GameAction diff --git a/frontend/src/redux/actions/all.ts b/frontend/src/redux/actions/all.ts new file mode 100644 index 00000000..57d2a443 --- /dev/null +++ b/frontend/src/redux/actions/all.ts @@ -0,0 +1,5 @@ +import { GameAction } from './game'; +import { LobbyAction } from './lobby'; +import { PlayerAction } from './user'; + +export type Action = PlayerAction | LobbyAction | GameAction diff --git a/frontend/src/redux/actions/game.js b/frontend/src/redux/actions/game.js deleted file mode 100644 index 434aa8d3..00000000 --- a/frontend/src/redux/actions/game.js +++ /dev/null @@ -1,34 +0,0 @@ -import type { ApiPlayerMove, ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../../api/model'; - -export const types = { - REQUEST_SAY_READY: 'GAME/REQUEST_SAY_READY', - REQUEST_PREPARE_MOVE: 'GAME/REQUEST_PREPARE_MOVE', - PLAYER_READY_RECEIVED: 'GAME/PLAYER_READY_RECEIVED', - TABLE_UPDATE_RECEIVED: 'GAME/TABLE_UPDATE_RECEIVED', - PREPARED_CARD_RECEIVED: 'GAME/PREPARED_CARD_RECEIVED', - TURN_INFO_RECEIVED: 'GAME/TURN_INFO_RECEIVED', -}; - -export type SayReadyAction = { type: 'GAME/REQUEST_SAY_READY' }; -export type PrepareMoveAction = { type: 'GAME/REQUEST_PREPARE_MOVE', move: ApiPlayerMove }; -export type PlayerReadyEvent = { type: 'GAME/PLAYER_READY_RECEIVED', username: string }; -export type TableUpdateEvent = { type: 'GAME/TABLE_UPDATE_RECEIVED', table: ApiTable }; -export type PreparedCardEvent = { type: 'GAME/PREPARED_CARD_RECEIVED', card: ApiPreparedCard }; -export type TurnInfoEvent = { type: 'GAME/TURN_INFO_RECEIVED', turnInfo: ApiPlayerTurnInfo }; - -export type GameAction = - SayReadyAction - | PrepareMoveAction - | PlayerReadyEvent - | TableUpdateEvent - | PreparedCardEvent - | TurnInfoEvent; - -export const actions = { - sayReady: () => ({ type: types.REQUEST_SAY_READY }), - prepareMove: (move: ApiPlayerMove) => ({ type: types.REQUEST_PREPARE_MOVE, move }), - receivePlayerReady: (username: string) => ({ type: types.PLAYER_READY_RECEIVED, username }), - receiveTableUpdate: (table: ApiTable) => ({ type: types.TABLE_UPDATE_RECEIVED, table }), - receivePreparedCard: (card: ApiPreparedCard) => ({ type: types.PREPARED_CARD_RECEIVED, card }), - receiveTurnInfo: (turnInfo: ApiPlayerTurnInfo) => ({ type: types.TURN_INFO_RECEIVED, turnInfo }), -}; diff --git a/frontend/src/redux/actions/game.ts b/frontend/src/redux/actions/game.ts new file mode 100644 index 00000000..b67ea1dc --- /dev/null +++ b/frontend/src/redux/actions/game.ts @@ -0,0 +1,32 @@ +import { ApiPlayerMove, ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../../api/model'; + +export const REQUEST_SAY_READY = 'GAME/REQUEST_SAY_READY'; +export const REQUEST_PREPARE_MOVE = 'GAME/REQUEST_PREPARE_MOVE'; +export const PLAYER_READY_RECEIVED = 'GAME/PLAYER_READY_RECEIVED'; +export const TABLE_UPDATE_RECEIVED = 'GAME/TABLE_UPDATE_RECEIVED'; +export const PREPARED_CARD_RECEIVED = 'GAME/PREPARED_CARD_RECEIVED'; +export const TURN_INFO_RECEIVED = 'GAME/TURN_INFO_RECEIVED'; + +export type SayReadyAction = { type: typeof REQUEST_SAY_READY }; +export type PrepareMoveAction = { type: typeof REQUEST_PREPARE_MOVE, move: ApiPlayerMove }; +export type PlayerReadyEvent = { type: typeof PLAYER_READY_RECEIVED, username: string }; +export type TableUpdateEvent = { type: typeof TABLE_UPDATE_RECEIVED, table: ApiTable }; +export type PreparedCardEvent = { type: typeof PREPARED_CARD_RECEIVED, card: ApiPreparedCard }; +export type TurnInfoEvent = { type: typeof TURN_INFO_RECEIVED, turnInfo: ApiPlayerTurnInfo }; + +export type GameAction = + SayReadyAction + | PrepareMoveAction + | PlayerReadyEvent + | TableUpdateEvent + | PreparedCardEvent + | TurnInfoEvent; + +export const actions = { + sayReady: () => ({ type: REQUEST_SAY_READY }), + prepareMove: (move: ApiPlayerMove) => ({ type: REQUEST_PREPARE_MOVE, move }), + receivePlayerReady: (username: string) => ({ type: PLAYER_READY_RECEIVED, username }), + receiveTableUpdate: (table: ApiTable) => ({ type: TABLE_UPDATE_RECEIVED, table }), + receivePreparedCard: (card: ApiPreparedCard) => ({ type: PREPARED_CARD_RECEIVED, card }), + receiveTurnInfo: (turnInfo: ApiPlayerTurnInfo) => ({ type: TURN_INFO_RECEIVED, turnInfo }), +}; diff --git a/frontend/src/redux/actions/lobby.js b/frontend/src/redux/actions/lobby.js deleted file mode 100644 index 8768ec80..00000000 --- a/frontend/src/redux/actions/lobby.js +++ /dev/null @@ -1,34 +0,0 @@ -import type { ApiLobby } from '../../api/model'; - -export const types = { - UPDATE_GAMES: 'GAMES/UPDATE_GAMES', - REQUEST_CREATE_GAME: 'GAMES/REQUEST_CREATE_GAME', - REQUEST_JOIN_GAME: 'GAMES/REQUEST_JOIN_GAME', - REQUEST_START_GAME: 'GAMES/REQUEST_START_GAME', - ENTER_LOBBY: 'GAMES/ENTER_LOBBY', - ENTER_GAME: 'GAMES/ENTER_GAME', -}; - -export type UpdateGamesAction = { type: 'GAMES/UPDATE_GAMES', games: ApiLobby[]}; -export type RequestCreateGameAction = { type: 'GAMES/REQUEST_CREATE_GAME', gameName: string }; -export type RequestJoinGameAction = { type: 'GAMES/REQUEST_JOIN_GAME', gameId: number }; -export type RequestStartGameAction = { type: 'GAMES/REQUEST_START_GAME' }; -export type EnterLobbyAction = { type: 'GAMES/ENTER_LOBBY', gameId: number }; -export type EnterGameAction = { type: 'GAMES/ENTER_GAME', gameId: number }; - -export type LobbyAction = - | UpdateGamesAction - | RequestCreateGameAction - | RequestJoinGameAction - | RequestStartGameAction - | EnterLobbyAction - | EnterGameAction; - -export const actions = { - updateGames: (games: ApiLobby[]): UpdateGamesAction => ({ type: types.UPDATE_GAMES, games }), - requestJoinGame: (gameId: number): RequestJoinGameAction => ({ type: types.REQUEST_JOIN_GAME, gameId }), - requestCreateGame: (gameName: string): RequestCreateGameAction => ({ type: types.REQUEST_CREATE_GAME, gameName }), - requestStartGame: (): RequestStartGameAction => ({ type: types.REQUEST_START_GAME }), - enterLobby: (gameId: number): EnterLobbyAction => ({ type: types.ENTER_LOBBY, gameId }), - enterGame: (gameId: number): EnterGameAction => ({ type: types.ENTER_GAME, gameId }), -}; diff --git a/frontend/src/redux/actions/lobby.ts b/frontend/src/redux/actions/lobby.ts new file mode 100644 index 00000000..c121b022 --- /dev/null +++ b/frontend/src/redux/actions/lobby.ts @@ -0,0 +1,32 @@ +import { ApiLobby } from '../../api/model'; + +export const UPDATE_GAMES = 'GAMES/UPDATE_GAMES'; +export const REQUEST_CREATE_GAME = 'GAMES/REQUEST_CREATE_GAME'; +export const REQUEST_JOIN_GAME = 'GAMES/REQUEST_JOIN_GAME'; +export const REQUEST_START_GAME = 'GAMES/REQUEST_START_GAME'; +export const ENTER_LOBBY = 'GAMES/ENTER_LOBBY'; +export const ENTER_GAME = 'GAMES/ENTER_GAME'; + +export type UpdateGamesAction = { type: typeof UPDATE_GAMES, games: ApiLobby[]}; +export type RequestCreateGameAction = { type: typeof REQUEST_CREATE_GAME, gameName: string }; +export type RequestJoinGameAction = { type: typeof REQUEST_JOIN_GAME, gameId: number }; +export type RequestStartGameAction = { type: typeof REQUEST_START_GAME }; +export type EnterLobbyAction = { type: typeof ENTER_LOBBY, gameId: number }; +export type EnterGameAction = { type: typeof ENTER_GAME, gameId: number }; + +export type LobbyAction = + | UpdateGamesAction + | RequestCreateGameAction + | RequestJoinGameAction + | RequestStartGameAction + | EnterLobbyAction + | EnterGameAction; + +export const actions = { + updateGames: (games: ApiLobby[]): UpdateGamesAction => ({ type: UPDATE_GAMES, games }), + requestJoinGame: (gameId: number): RequestJoinGameAction => ({ type: REQUEST_JOIN_GAME, gameId }), + requestCreateGame: (gameName: string): RequestCreateGameAction => ({ type: REQUEST_CREATE_GAME, gameName }), + requestStartGame: (): RequestStartGameAction => ({ type: REQUEST_START_GAME }), + enterLobby: (gameId: number): EnterLobbyAction => ({ type: ENTER_LOBBY, gameId }), + enterGame: (gameId: number): EnterGameAction => ({ type: ENTER_GAME, gameId }), +}; diff --git a/frontend/src/redux/actions/user.js b/frontend/src/redux/actions/user.js deleted file mode 100644 index 4406230b..00000000 --- a/frontend/src/redux/actions/user.js +++ /dev/null @@ -1,25 +0,0 @@ -import { Map } from 'immutable'; -import type { ApiPlayer } from '../../api/model'; - -export const types = { - REQUEST_CHOOSE_USERNAME: 'USER/REQUEST_CHOOSE_USERNAME', - SET_CURRENT_PLAYER: 'USER/SET_CURRENT_PLAYER', - UPDATE_PLAYERS: 'USER/UPDATE_PLAYERS', -}; - -export type RequestChooseUsernameAction = { type: types.REQUEST_CHOOSE_USERNAME, username: string }; -export type SetCurrentPlayerAction = { type: types.SET_CURRENT_PLAYER, player: ApiPlayer }; -export type UpdatePlayersAction = { type: types.UPDATE_PLAYERS, players: Map<string, ApiPlayer> }; - -export type PlayerAction = RequestChooseUsernameAction | SetCurrentPlayerAction | UpdatePlayersAction; - -export const actions = { - chooseUsername: (username: string): RequestChooseUsernameAction => ({ - type: types.REQUEST_CHOOSE_USERNAME, - username, - }), - setCurrentPlayer: (player: ApiPlayer): SetCurrentPlayerAction => ({ - type: types.SET_CURRENT_PLAYER, - player: player, - }), -}; diff --git a/frontend/src/redux/actions/user.ts b/frontend/src/redux/actions/user.ts new file mode 100644 index 00000000..29c85707 --- /dev/null +++ b/frontend/src/redux/actions/user.ts @@ -0,0 +1,17 @@ +import { Map } from 'immutable'; +import { ApiPlayer } from '../../api/model'; + +export const REQUEST_CHOOSE_USERNAME = 'USER/REQUEST_CHOOSE_USERNAME'; +export const SET_CURRENT_PLAYER = 'USER/SET_CURRENT_PLAYER'; +export const UPDATE_PLAYERS = 'USER/UPDATE_PLAYERS'; + +export type RequestChooseUsernameAction = { type: typeof REQUEST_CHOOSE_USERNAME, username: string }; +export type SetCurrentPlayerAction = { type: typeof SET_CURRENT_PLAYER, player: ApiPlayer }; +export type UpdatePlayersAction = { type: typeof UPDATE_PLAYERS, players: Map<string, ApiPlayer> }; + +export type PlayerAction = RequestChooseUsernameAction | SetCurrentPlayerAction | UpdatePlayersAction; + +export const actions = { + chooseUsername: (username: string): RequestChooseUsernameAction => ({ type: REQUEST_CHOOSE_USERNAME, username }), + setCurrentPlayer: (player: ApiPlayer): SetCurrentPlayerAction => ({ type: SET_CURRENT_PLAYER, player }), +}; diff --git a/frontend/src/redux/currentGame.js b/frontend/src/redux/currentGame.js index e315a1e8..21b7108e 100644 --- a/frontend/src/redux/currentGame.js +++ b/frontend/src/redux/currentGame.js @@ -3,7 +3,7 @@ import { combineReducers } from 'redux'; import type { ApiPlayerTurnInfo, ApiTable } from '../api/model'; import type { GlobalState } from '../reducers'; import type { Action } from './actions/all'; -import { types } from './actions/game'; +import { TABLE_UPDATE_RECEIVED, TURN_INFO_RECEIVED } from './actions/game'; export type CurrentGameState = { turnInfo: ApiPlayerTurnInfo | null; @@ -19,9 +19,9 @@ export function createCurrentGameReducer() { const turnInfoReducer = (state: ApiPlayerTurnInfo | null = null, action: Action) => { switch (action.type) { - case types.TURN_INFO_RECEIVED: + case TURN_INFO_RECEIVED: return action.turnInfo; - case types.TABLE_UPDATE_RECEIVED: + case TABLE_UPDATE_RECEIVED: return null; default: return state; @@ -30,9 +30,9 @@ const turnInfoReducer = (state: ApiPlayerTurnInfo | null = null, action: Action) const tableUpdatesReducer = (state: ApiTable | null = null, action: Action) => { switch (action.type) { - case types.TURN_INFO_RECEIVED: + case TURN_INFO_RECEIVED: return action.turnInfo.table; - case types.TABLE_UPDATE_RECEIVED: + case TABLE_UPDATE_RECEIVED: return action.table; default: return state; diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js index f5543a76..b5b0c7fc 100644 --- a/frontend/src/redux/games.js +++ b/frontend/src/redux/games.js @@ -4,7 +4,7 @@ import { combineReducers } from 'redux'; import type { ApiLobby } from '../api/model'; import type { GlobalState } from '../reducers'; import type { Action } from './actions/all'; -import { types } from './actions/lobby'; +import { ENTER_LOBBY, UPDATE_GAMES } from './actions/lobby'; export type GamesState = { all: Map<string, ApiLobby>, @@ -20,7 +20,7 @@ export const createGamesReducer = () => { export const allGamesReducer = (state: Map<string, ApiLobby> = Map(), action: Action) => { switch (action.type) { - case types.UPDATE_GAMES: + case UPDATE_GAMES: let newGames = {}; action.games.forEach(g => newGames[g.id] = g); return state.merge(Map(newGames)); @@ -31,7 +31,7 @@ export const allGamesReducer = (state: Map<string, ApiLobby> = Map(), action: Ac export const currentGameIdReducer = (state: string | void = null, action: Action) => { switch (action.type) { - case types.ENTER_LOBBY: + case ENTER_LOBBY: return `${action.gameId}`; default: return state; diff --git a/frontend/src/redux/user.js b/frontend/src/redux/user.js index f2247b38..0876d4c2 100644 --- a/frontend/src/redux/user.js +++ b/frontend/src/redux/user.js @@ -1,7 +1,7 @@ import { ApiPlayer } from '../api/model'; import type { GlobalState } from '../reducers'; import type { Action } from './actions/all'; -import { types } from './actions/user'; +import { SET_CURRENT_PLAYER } from './actions/user'; import { getCurrentGame } from './games'; export type User = { @@ -11,7 +11,7 @@ export type User = { export const currentUserReducer = (state: ?User = null, action: Action) => { switch (action.type) { - case types.SET_CURRENT_PLAYER: + case SET_CURRENT_PLAYER: return { username: action.player.username, displayName: action.player.displayName diff --git a/frontend/src/sagas/game.js b/frontend/src/sagas/game.js index dc92e89a..661c277b 100644 --- a/frontend/src/sagas/game.js +++ b/frontend/src/sagas/game.js @@ -2,9 +2,8 @@ import { eventChannel } from 'redux-saga'; import { apply, call, put, take } from 'redux-saga/effects'; import type { ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../api/model'; import { SevenWondersSession } from '../api/sevenWondersApi'; -import { actions } from '../redux/actions/game'; -import { types } from '../redux/actions/game'; -import { types as gameTypes } from '../redux/actions/lobby'; +import { actions, REQUEST_PREPARE_MOVE, REQUEST_SAY_READY } from '../redux/actions/game'; +import { ENTER_GAME } from '../redux/actions/lobby'; function* watchPlayerReady(session: SevenWondersSession, gameId: number) { const channel = yield eventChannel(session.watchPlayerReady(gameId)); @@ -44,14 +43,14 @@ function* watchPreparedCards(session: SevenWondersSession, gameId: number) { function* sayReady(session: SevenWondersSession) { while (true) { - yield take(types.REQUEST_SAY_READY); + yield take(REQUEST_SAY_READY); yield apply(session, session.sayReady); } } function* prepareMove(session: SevenWondersSession) { while (true) { - let action = yield take(types.REQUEST_PREPARE_MOVE); + let action = yield take(REQUEST_PREPARE_MOVE); yield apply(session, session.prepareMove, [action.move]); } } @@ -69,7 +68,7 @@ function* watchTurnInfo(session: SevenWondersSession) { } export function* gameSaga(session: SevenWondersSession) { - const { gameId } = yield take(gameTypes.ENTER_GAME); + const { gameId } = yield take(ENTER_GAME); console.log('Entered game!', gameId); yield [ call(watchPlayerReady, session, gameId), diff --git a/frontend/src/sagas/gameBrowser.js b/frontend/src/sagas/gameBrowser.js index fec83451..6b545933 100644 --- a/frontend/src/sagas/gameBrowser.js +++ b/frontend/src/sagas/gameBrowser.js @@ -5,7 +5,7 @@ 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, types } from '../redux/actions/lobby'; +import { actions as gameActions, REQUEST_CREATE_GAME, REQUEST_JOIN_GAME } from '../redux/actions/lobby'; function* watchGames(session: SevenWondersSession): SagaIterator { const gamesChannel = yield eventChannel(session.watchGames()); @@ -33,7 +33,7 @@ function* watchLobbyJoined(session: SevenWondersSession): SagaIterator { function* createGame(session: SevenWondersSession): SagaIterator { while (true) { - const { gameName } = yield take(types.REQUEST_CREATE_GAME); + const { gameName } = yield take(REQUEST_CREATE_GAME); // $FlowFixMe yield apply(session, session.createGame, [gameName]); } @@ -41,7 +41,7 @@ function* createGame(session: SevenWondersSession): SagaIterator { function* joinGame(session: SevenWondersSession): SagaIterator { while (true) { - const { gameId } = yield take(types.REQUEST_JOIN_GAME); + const { gameId } = yield take(REQUEST_JOIN_GAME); // $FlowFixMe yield apply(session, session.joinGame, [gameId]); } diff --git a/frontend/src/sagas/home.js b/frontend/src/sagas/home.js index 43ab97dc..237ca004 100644 --- a/frontend/src/sagas/home.js +++ b/frontend/src/sagas/home.js @@ -5,12 +5,11 @@ import { eventChannel } from 'redux-saga'; import { all, apply, call, put, take } from 'redux-saga/effects'; import type { ApiPlayer } from '../api/model'; import type { SevenWondersSession } from '../api/sevenWondersApi'; -import { actions } from '../redux/actions/user'; -import { types } from '../redux/actions/user'; +import { actions, REQUEST_CHOOSE_USERNAME } from '../redux/actions/user'; function* sendUsername(session: SevenWondersSession): SagaIterator { while (true) { - const { username } = yield take(types.REQUEST_CHOOSE_USERNAME); + const { username } = yield take(REQUEST_CHOOSE_USERNAME); // $FlowFixMe yield apply(session, session.chooseName, [username]); } diff --git a/frontend/src/sagas/lobby.js b/frontend/src/sagas/lobby.js index 7ff94f34..ce840947 100644 --- a/frontend/src/sagas/lobby.js +++ b/frontend/src/sagas/lobby.js @@ -4,7 +4,7 @@ import type { Channel, SagaIterator } from 'redux-saga'; import { eventChannel } from 'redux-saga'; import { all, apply, call, put, take } from 'redux-saga/effects'; import { SevenWondersSession } from '../api/sevenWondersApi'; -import { actions as gameActions, types } from '../redux/actions/lobby'; +import { actions as gameActions, ENTER_LOBBY, REQUEST_START_GAME } from '../redux/actions/lobby'; function* watchLobbyUpdates(session: SevenWondersSession, lobbyId: number): SagaIterator { const lobbyUpdatesChannel: Channel = yield eventChannel(session.watchLobbyUpdated(lobbyId)); @@ -31,13 +31,13 @@ function* watchGameStart(session: SevenWondersSession, lobbyId: number): SagaIte function* startGame(session: SevenWondersSession): SagaIterator { while (true) { - yield take(types.REQUEST_START_GAME); + yield take(REQUEST_START_GAME); yield apply(session, session.startGame, []); } } export function* lobbySaga(session: SevenWondersSession): SagaIterator { - const { gameId } = yield take(types.ENTER_LOBBY); + const { gameId } = yield take(ENTER_LOBBY); yield all([ call(watchLobbyUpdates, session, gameId), call(watchGameStart, session, gameId), |