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

Make AJAX request when mounting ChessBoard

This commit is contained in:
Rob Whittaker 2016-12-09 11:40:25 +00:00 committed by Dan Barber
parent 27444fc154
commit 02ad2c951b
5 changed files with 26 additions and 1 deletions

View File

@ -8,6 +8,7 @@
"dependencies": { "dependencies": {
"classnames": "^2.2.5", "classnames": "^2.2.5",
"immutable": "^3.8.1", "immutable": "^3.8.1",
"jquery": "^3.1.1",
"lodash": "^4.17.2", "lodash": "^4.17.2",
"phoenix": "file:deps/phoenix", "phoenix": "file:deps/phoenix",
"phoenix_html": "file:deps/phoenix_html", "phoenix_html": "file:deps/phoenix_html",

View File

@ -0,0 +1,9 @@
defmodule Chess.GameController do
use Chess.Web, :controller
alias Chess.Game
def show(conn, _params) do
render conn, "show.json", id: 1
end
end

View File

@ -16,7 +16,7 @@ class App extends React.Component {
const { store } = this.props; const { store } = this.props;
return ( return (
<ChessBoard store={store} /> <ChessBoard gameId={1} store={store} />
); );
} }
} }

View File

@ -1,9 +1,17 @@
import React from "react"; import React from "react";
import $ from "jquery";
import { connect } from "react-redux"; import { connect } from "react-redux";
import ChessBoardSquare from "./chess-board-square"; import ChessBoardSquare from "./chess-board-square";
class ChessBoard extends React.Component { class ChessBoard extends React.Component {
componentWillMount() {
const { gameId } = this.props;
$.ajax({ method: "GET", url: "/games/" + gameId })
.then(() => console.log("Oh, hai!"));
}
getBoard() { getBoard() {
const { store } = this.props; const { store } = this.props;
return store.getState().board; return store.getState().board;

7
web/views/game_view.ex Normal file
View File

@ -0,0 +1,7 @@
defmodule Chess.GameView do
use Chess.Web, :view
def render("show.json", %{ id: 1 }) do
%{ foo: :bar }
end
end