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

Render moves directly from the fucking server

This commit is contained in:
Rob Whittaker 2016-12-09 16:09:07 +00:00 committed by Dan Barber
parent 66b07454ed
commit 7130e74516

View File

@ -2,7 +2,7 @@ import React from "react";
import $ from "jquery"; import $ from "jquery";
import classNames from "classnames"; import classNames from "classnames";
import { movePiece, selectPiece } from "../store/actions"; import { selectPiece, setBoard } from "../store/actions";
class ChessBoardSquare extends React.Component { class ChessBoardSquare extends React.Component {
constructor(props) { constructor(props) {
@ -20,13 +20,11 @@ class ChessBoardSquare extends React.Component {
var { gameId, selectedSquare } = store.getState(); var { gameId, selectedSquare } = store.getState();
if (selectedSquare != null) { if (selectedSquare != null) {
store.dispatch(movePiece(selectedSquare, this.squareCoords()));
$.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(setBoard(data)));
} }
else if (piece != undefined) { else if (piece != undefined) {
store.dispatch(selectPiece(this.squareCoords())); store.dispatch(selectPiece(this.squareCoords()));