import React from "react"; import $ from "jquery"; import { connect } from "react-redux"; import ChessBoardSquare from "./chess-board-square"; class ChessBoard extends React.Component { componentWillMount() { const { gameId } = this.props; $.ajax({ method: "GET", url: "/api/games/" + gameId }) .then(() => console.log("Oh, hai!")); } getBoard() { const { store } = this.props; return store.getState().board; } renderFiles(rankId) { const { store } = this.props; const rank = this.getBoard()[rankId]; return Object.keys(rank).map((fileId) => { return ( ); }); } renderRanks() { const board = this.getBoard(); return Object.keys(board).reverse().map((rankId) => { return (
{this.renderFiles(rankId)}
); }); } render() { return
{this.renderRanks()}
; } } function mapStateToProps(state) { return { selectedSquare: state.selectedSquare } } export default connect(mapStateToProps)(ChessBoard);