diff --git a/assets/js/app.js b/assets/js/app.js
index 686b26a..fd0c663 100644
--- a/assets/js/app.js
+++ b/assets/js/app.js
@@ -13,6 +13,7 @@ import chessBoardReducer from "./reducers/chess-board";
import { setGameId } from "./store/actions";
import ChessBoard from "./components/chess-board";
+import MoveList from "./components/move-list";
const store = createStore(chessBoardReducer);
@@ -25,15 +26,24 @@ class App extends React.Component {
this.channel = new Channel(store, gameId);
}
+ get moves() {
+ const { store } = this.props;
+ return store.getState().moves;
+ }
+
render() {
const { store, gameId } = this.props;
return (
-
+
+
+
+
+
);
}
}
diff --git a/assets/js/components/move-list.js b/assets/js/components/move-list.js
new file mode 100644
index 0000000..187dbbf
--- /dev/null
+++ b/assets/js/components/move-list.js
@@ -0,0 +1,27 @@
+import React from "react";
+import { connect } from "react-redux";
+import _ from "lodash";
+
+const renderMoves = (moves) => {
+ return _.map(moves, (move) => {
+ return (
+ {move}
+ );
+ });
+};
+
+const MoveList = (props) => {
+ return (
+
+ {renderMoves(props.moves)}
+
+ );
+};
+
+function mapStateToProps(state) {
+ return {
+ moves: state.moves,
+ };
+}
+
+export default connect(mapStateToProps)(MoveList);
diff --git a/assets/js/reducers/chess-board.js b/assets/js/reducers/chess-board.js
index 4519338..beb47eb 100644
--- a/assets/js/reducers/chess-board.js
+++ b/assets/js/reducers/chess-board.js
@@ -15,7 +15,8 @@ const chessBoardReducer = (state = defaultState, action) => {
.set("turn", action.turn)
.set("state", action.state)
.set("selectedSquare", null)
- .set("moves", [])
+ .set("availableMoves", [])
+ .set("moves", action.moves)
.toJS();
case "SET_AVAILABLE_MOVES":
@@ -31,7 +32,7 @@ const chessBoardReducer = (state = defaultState, action) => {
case "SELECT_PIECE":
return Immutable.fromJS(state)
.set("selectedSquare", action.coords)
- .set("moves", [])
+ .set("availableMoves", [])
.toJS();
default:
diff --git a/assets/js/services/channel.js b/assets/js/services/channel.js
index 72ce905..73989c1 100644
--- a/assets/js/services/channel.js
+++ b/assets/js/services/channel.js
@@ -1,5 +1,5 @@
import socket from "../socket";
-import { setPlayer, setGame, setMoves } from "../store/actions";
+import { setPlayer, setGame, setAvailableMoves } from "../store/actions";
class Channel {
constructor(store, gameId) {
diff --git a/assets/js/store/actions.js b/assets/js/store/actions.js
index 400e4c2..c4b1b0c 100644
--- a/assets/js/store/actions.js
+++ b/assets/js/store/actions.js
@@ -16,6 +16,7 @@ export const setGame = (data) => {
type: SET_GAME,
board: data.board,
turn: data.turn,
+ moves: data.moves,
state: data.state,
};
};
diff --git a/assets/js/store/default-state.js b/assets/js/store/default-state.js
index 743c392..0dfc0f2 100644
--- a/assets/js/store/default-state.js
+++ b/assets/js/store/default-state.js
@@ -7,6 +7,8 @@ const defaultState = {
availableMoves: [],
+ moves: [],
+
board: {
8: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
7: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },