2020-12-27 20:11:50 -05:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2021-01-06 08:44:34 -05:00
|
|
|
import io from 'socket.io-client';
|
2021-01-01 20:03:56 -05:00
|
|
|
|
2021-01-02 10:15:03 -05:00
|
|
|
import Board from './board';
|
2021-01-01 20:03:56 -05:00
|
|
|
|
2020-12-27 20:11:50 -05:00
|
|
|
import './index.css';
|
|
|
|
|
2021-01-01 20:03:56 -05:00
|
|
|
|
2021-01-06 08:44:34 -05:00
|
|
|
const ENDPOINT = "http://192.168.1.7:4001";
|
|
|
|
|
2020-12-27 20:11:50 -05:00
|
|
|
class Game extends React.Component {
|
2021-01-06 08:44:34 -05:00
|
|
|
constructor(props) {
|
2021-01-01 20:03:56 -05:00
|
|
|
super(props);
|
2021-01-06 08:44:34 -05:00
|
|
|
this.state = {
|
|
|
|
board: null,
|
|
|
|
socket: io(ENDPOINT),
|
|
|
|
};
|
|
|
|
|
|
|
|
this.state.socket.on("FromAPI", data => {
|
|
|
|
console.log(data);
|
|
|
|
this.setState({
|
|
|
|
board: null,
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
board: (
|
|
|
|
<Board
|
|
|
|
text={data}
|
|
|
|
onMove={(move) => {
|
|
|
|
console.log("ON MOVE");
|
|
|
|
this.state.socket.emit("move", move);
|
|
|
|
}}/>
|
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
2021-01-01 20:03:56 -05:00
|
|
|
}
|
|
|
|
|
2020-12-27 20:11:50 -05:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="game">
|
2020-12-28 16:41:13 -05:00
|
|
|
<div className="game-board">
|
2021-01-06 08:44:34 -05:00
|
|
|
{this.state.board}
|
2020-12-28 16:41:13 -05:00
|
|
|
</div>
|
2020-12-27 20:11:50 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<Game />,
|
|
|
|
document.getElementById('root')
|
|
|
|
);
|