mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Tidy up chess board
This commit is contained in:
parent
87b2a2d5c9
commit
4e78fad7dc
@ -3,33 +3,40 @@ import React from "react";
|
|||||||
import ChessBoardSquare from "components/chess-board-square";
|
import ChessBoardSquare from "components/chess-board-square";
|
||||||
|
|
||||||
class ChessBoard extends React.Component {
|
class ChessBoard extends React.Component {
|
||||||
constructor(props) {
|
getBoard() {
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
chessBoardRows() {
|
|
||||||
const { store } = this.props;
|
const { store } = this.props;
|
||||||
return store.getState().board;
|
return store.getState().board;
|
||||||
}
|
}
|
||||||
|
|
||||||
chessBoardRow(row, rank) {
|
renderFiles(rankId) {
|
||||||
return (
|
const rank = this.getBoard()[rankId];
|
||||||
<div className="board-rank" key={rank}>
|
|
||||||
{Object.keys(row).map(
|
return Object.keys(rank).map((fileId) => {
|
||||||
(file) => <ChessBoardSquare key={file} rank={rank} file={file} square={row[file]} />
|
return (
|
||||||
)}
|
<ChessBoardSquare
|
||||||
</div>
|
file={fileId}
|
||||||
)
|
key={fileId}
|
||||||
|
rank={rankId}
|
||||||
|
square={rank[fileId]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
renderRanks() {
|
||||||
|
const board = this.getBoard();
|
||||||
|
|
||||||
|
return Object.keys(board).reverse().map((rankId) => {
|
||||||
|
return (
|
||||||
|
<div className="board-rank" key={rankId}>
|
||||||
|
{this.renderFiles(rankId)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return <div className="board">{this.renderRanks()}</div>;
|
||||||
<div className="board">
|
|
||||||
{Object.keys(this.chessBoardRows()).reverse().map(
|
|
||||||
(rank) => this.chessBoardRow(this.chessBoardRows()[rank], rank)
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user