1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Respond to feedback

This commit is contained in:
Daniel Barber 2018-03-02 13:02:40 -05:00
parent eb04f275e2
commit dcff5712b8
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 14 additions and 14 deletions

View File

@ -10,24 +10,24 @@ class ChessBoardSquare extends React.Component {
super(props);
}
squareCoords() {
get squareCoords() {
return [this.props.file, this.props.rank];
}
selectSquare() {
let { piece, store } = this.props;
let { gameId, selectedSquare, player } = store.getState();
const { piece, store } = this.props;
const { gameId, selectedSquare, player } = store.getState();
if (selectedSquare != null && this.moveIsValid()) {
$.ajax({
method: "PATCH",
url: "/api/games/" + gameId,
data: { move: { from: selectedSquare, to: this.squareCoords() } },
data: { move: { from: selectedSquare, to: this.squareCoords } },
}).then((data) => store.dispatch(setGame(data)));
} else if (selectedSquare != null) {
store.dispatch(selectPiece(null));
} else if (this.playerCanSelectPiece(player, piece)) {
store.dispatch(selectPiece(this.squareCoords()));
store.dispatch(selectPiece(this.squareCoords));
}
}
@ -36,8 +36,8 @@ class ChessBoardSquare extends React.Component {
}
playerCanSelectPiece(player, piece) {
let { store } = this.props;
let { turn } = store.getState();
const { store } = this.props;
const { turn } = store.getState();
return piece !== undefined &&
piece.colour == player &&
@ -45,12 +45,12 @@ class ChessBoardSquare extends React.Component {
}
isSelectedSquare() {
let { store } = this.props;
const { store } = this.props;
if (store.getState().selectedSquare == null) {
return false;
} else {
return _.isEqual(this.squareCoords(), store.getState().selectedSquare);
return _.isEqual(this.squareCoords, store.getState().selectedSquare);
}
}
@ -58,7 +58,7 @@ class ChessBoardSquare extends React.Component {
return `f${this.props.file}-r${this.props.rank}`;
}
squareClass() {
get squareClass() {
if (this.props.piece == undefined) {
return "board-square";
} else {
@ -74,7 +74,7 @@ class ChessBoardSquare extends React.Component {
render() {
return <div
id={this.squareId()}
className={this.squareClass()}
className={this.squareClass}
onClick={this.selectSquare.bind(this)}
/>;
}

View File

@ -22,7 +22,7 @@ class ChessBoard extends React.Component {
store.dispatch(setGame(data));
});
this.channel = socket.channel("game:" + gameId, {});
this.channel = socket.channel(`game:${gameId}`, {});
this.channel.join()
.receive("error", resp => {
console.log("Unable to join", resp);
@ -102,7 +102,7 @@ class ChessBoard extends React.Component {
}
}
boardClass() {
get boardClass() {
const turn = this.getTurn();
const player = this.getPlayer();
@ -111,7 +111,7 @@ class ChessBoard extends React.Component {
render() {
return (
<div className={this.boardClass()}>
<div className={this.boardClass}>
<div className="board-header">
<div className="board-border-top" />
</div>