mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
Respond to feedback
This commit is contained in:
parent
eb04f275e2
commit
dcff5712b8
@ -10,24 +10,24 @@ class ChessBoardSquare extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
squareCoords() {
|
get squareCoords() {
|
||||||
return [this.props.file, this.props.rank];
|
return [this.props.file, this.props.rank];
|
||||||
}
|
}
|
||||||
|
|
||||||
selectSquare() {
|
selectSquare() {
|
||||||
let { piece, store } = this.props;
|
const { piece, store } = this.props;
|
||||||
let { gameId, selectedSquare, player } = store.getState();
|
const { gameId, selectedSquare, player } = store.getState();
|
||||||
|
|
||||||
if (selectedSquare != null && this.moveIsValid()) {
|
if (selectedSquare != null && this.moveIsValid()) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
url: "/api/games/" + gameId,
|
url: "/api/games/" + gameId,
|
||||||
data: { move: { from: selectedSquare, to: this.squareCoords() } },
|
data: { move: { from: selectedSquare, to: this.squareCoords } },
|
||||||
}).then((data) => store.dispatch(setGame(data)));
|
}).then((data) => store.dispatch(setGame(data)));
|
||||||
} else if (selectedSquare != null) {
|
} else if (selectedSquare != null) {
|
||||||
store.dispatch(selectPiece(null));
|
store.dispatch(selectPiece(null));
|
||||||
} else if (this.playerCanSelectPiece(player, piece)) {
|
} 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) {
|
playerCanSelectPiece(player, piece) {
|
||||||
let { store } = this.props;
|
const { store } = this.props;
|
||||||
let { turn } = store.getState();
|
const { turn } = store.getState();
|
||||||
|
|
||||||
return piece !== undefined &&
|
return piece !== undefined &&
|
||||||
piece.colour == player &&
|
piece.colour == player &&
|
||||||
@ -45,12 +45,12 @@ class ChessBoardSquare extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isSelectedSquare() {
|
isSelectedSquare() {
|
||||||
let { store } = this.props;
|
const { store } = this.props;
|
||||||
|
|
||||||
if (store.getState().selectedSquare == null) {
|
if (store.getState().selectedSquare == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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}`;
|
return `f${this.props.file}-r${this.props.rank}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
squareClass() {
|
get squareClass() {
|
||||||
if (this.props.piece == undefined) {
|
if (this.props.piece == undefined) {
|
||||||
return "board-square";
|
return "board-square";
|
||||||
} else {
|
} else {
|
||||||
@ -74,7 +74,7 @@ class ChessBoardSquare extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return <div
|
return <div
|
||||||
id={this.squareId()}
|
id={this.squareId()}
|
||||||
className={this.squareClass()}
|
className={this.squareClass}
|
||||||
onClick={this.selectSquare.bind(this)}
|
onClick={this.selectSquare.bind(this)}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class ChessBoard extends React.Component {
|
|||||||
store.dispatch(setGame(data));
|
store.dispatch(setGame(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.channel = socket.channel("game:" + gameId, {});
|
this.channel = socket.channel(`game:${gameId}`, {});
|
||||||
this.channel.join()
|
this.channel.join()
|
||||||
.receive("error", resp => {
|
.receive("error", resp => {
|
||||||
console.log("Unable to join", resp);
|
console.log("Unable to join", resp);
|
||||||
@ -102,7 +102,7 @@ class ChessBoard extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boardClass() {
|
get boardClass() {
|
||||||
const turn = this.getTurn();
|
const turn = this.getTurn();
|
||||||
const player = this.getPlayer();
|
const player = this.getPlayer();
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ class ChessBoard extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className={this.boardClass()}>
|
<div className={this.boardClass}>
|
||||||
<div className="board-header">
|
<div className="board-header">
|
||||||
<div className="board-border-top" />
|
<div className="board-border-top" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user