add endGame function to FE

This commit is contained in:
sorrelbri 2020-06-20 16:56:03 -07:00
parent 52762475f7
commit 692a8b1400
4 changed files with 9 additions and 7 deletions

View file

@ -46,7 +46,7 @@ const launch = (nsp, dispatch) => {
dispatch({ type: "GAMES", message: "GAME_RESIGN", body: data });
});
socket.on("game_end", (data) => {
socket.on("end_game", (data) => {
dispatch({ type: "GAMES", message: "GAME_END", body: data });
});

View file

@ -24,8 +24,7 @@ export const gamesReducer = (state, action) => {
}
case "GAME_END": {
console.log(action.body);
return state;
return gameEnd(state, action);
}
default: {
@ -103,3 +102,9 @@ function gameResign(state, action) {
meta: { gameRecord, pass, turn, winner, playerState },
};
}
function gameEnd(state, action) {
console.log(action);
const { winner, score } = action.body.meta;
return { ...state, meta: { ...state.meta, winner, score } };
}

View file

@ -235,6 +235,7 @@ const Game = ({ gameData = {}, gameRecord = [] } = {}) => {
boardSize: this.boardSize,
handicap: this.handicap,
komi: this.komi,
score: this.score,
};
},

View file

@ -126,10 +126,6 @@ io.on("connection", async (socket) => {
});
} catch (e) {
console.log(e);
} finally {
socket.join(gameNsp, () => {
io.of(room).to(gameNsp).emit("end_game", { board, meta });
});
}
});
});