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:
parent
27444fc154
commit
02ad2c951b
@ -8,6 +8,7 @@
|
||||
"dependencies": {
|
||||
"classnames": "^2.2.5",
|
||||
"immutable": "^3.8.1",
|
||||
"jquery": "^3.1.1",
|
||||
"lodash": "^4.17.2",
|
||||
"phoenix": "file:deps/phoenix",
|
||||
"phoenix_html": "file:deps/phoenix_html",
|
||||
|
||||
9
web/controllers/game_controller.ex
Normal file
9
web/controllers/game_controller.ex
Normal 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
|
||||
@ -16,7 +16,7 @@ class App extends React.Component {
|
||||
const { store } = this.props;
|
||||
|
||||
return (
|
||||
<ChessBoard store={store} />
|
||||
<ChessBoard gameId={1} store={store} />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,17 @@
|
||||
import React from "react";
|
||||
import $ from "jquery";
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import ChessBoardSquare from "./chess-board-square";
|
||||
|
||||
class ChessBoard extends React.Component {
|
||||
componentWillMount() {
|
||||
const { gameId } = this.props;
|
||||
|
||||
$.ajax({ method: "GET", url: "/games/" + gameId })
|
||||
.then(() => console.log("Oh, hai!"));
|
||||
}
|
||||
|
||||
getBoard() {
|
||||
const { store } = this.props;
|
||||
return store.getState().board;
|
||||
|
||||
7
web/views/game_view.ex
Normal file
7
web/views/game_view.ex
Normal file
@ -0,0 +1,7 @@
|
||||
defmodule Chess.GameView do
|
||||
use Chess.Web, :view
|
||||
|
||||
def render("show.json", %{ id: 1 }) do
|
||||
%{ foo: :bar }
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user