diff options
Diffstat (limited to 'frontend/src/containers/GameBrowser')
-rw-r--r-- | frontend/src/containers/GameBrowser/actions.js | 16 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/constants.js | 3 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/index.js | 31 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/reducer.js | 13 | ||||
-rw-r--r-- | frontend/src/containers/GameBrowser/saga.js | 75 |
5 files changed, 0 insertions, 138 deletions
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/index.js b/frontend/src/containers/GameBrowser/index.js deleted file mode 100644 index 9deb720b..00000000 --- a/frontend/src/containers/GameBrowser/index.js +++ /dev/null @@ -1,31 +0,0 @@ -import React, { Component } from 'react' -import { connect } from 'react-redux' -import { Flex } from 'reflexbox' -import { Text, Space } from 'rebass' - -class GameBrowser extends Component { - - listGames = (games) => { - return games.valueSeq().map((game, index) => { - return (<Flex key={index}> - <Text>{game.get('name')}</Text> - <Space auto /> - <a href="#">Join</a> - </Flex>) - }) - } - - render() { - return ( - <div> - {this.listGames(this.props.games)} - </div> - ) - } -} - -const mapStateToProps = (state) => ({ - games: state.games -}) - -export default connect(mapStateToProps, {})(GameBrowser) 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/GameBrowser/saga.js b/frontend/src/containers/GameBrowser/saga.js deleted file mode 100644 index 4cd3d207..00000000 --- a/frontend/src/containers/GameBrowser/saga.js +++ /dev/null @@ -1,75 +0,0 @@ -import { call, put, take } from 'redux-saga/effects' -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' - -function createSocketChannel(socket) { - return eventChannel(emit => { - const makeHandler = (type) => (event) => { - const response = fromJS(JSON.parse(event.body)) - - emit({ - type, - response - }) - } - - const newGameHandler = makeHandler(NEW_GAME) - const joinGameHandler = makeHandler(JOIN_GAME) - - const newGame = socket.subscribe('/topic/games', newGameHandler) - const joinGame = socket.subscribe('/user/queue/join-game', joinGameHandler) - - const unsubscribe = () => { - newGame.unsubscribe() - joinGame.unsubscribe() - } - - return unsubscribe - }) -} - -export function* watchGames(socketConnection) { - - const { socket } = socketConnection - const socketChannel = createSocketChannel(socket) - - while (true) { - const { type, response } = yield take(socketChannel) - - switch (type) { - case NEW_GAME: - yield put(newGame(response)) - break; - case JOIN_GAME: - yield put(joinGame(response)) - break; - default: - console.error('Unknown type') - } - } -} - -export function* createGame(socketConnection) { - const { name } = yield take(CREATE_GAME) - const { socket } = socketConnection - - socket.send("/app/lobby/create-game", JSON.stringify({ - 'gameName': name, - 'playerName': 'Cesar92' - }), {}) -} - -export function* gameBrowserSaga(socketConnection) { - yield put(push('/lobby')) - - yield [ - call(watchGames, socketConnection), - call(createGame, socketConnection) - ] -} - -export default gameBrowserSaga |