Skip to content
Snippets Groups Projects
Commit edd726cc authored by L4929's avatar L4929
Browse files

Moved ClientSocket to GameView.js, along with getSocketSignal function and socketSignal state

parent b031a9c9
No related branches found
No related tags found
2 merge requests!31Development,!29Fixed socket functionality
import React, { Component } from "react"; import React, { Component } from "react";
import "../node_modules/leaflet-draw/dist/leaflet.draw.css"; import "../node_modules/leaflet-draw/dist/leaflet.draw.css";
import "./App.css"; import "./App.css";
import ClientSocket from "./components/Socket";
import { import {
BrowserRouter as Router, BrowserRouter as Router,
Route, Route,
...@@ -46,21 +45,6 @@ export default class App extends Component { ...@@ -46,21 +45,6 @@ export default class App extends Component {
}); });
}; };
// setting the socket signal automatically fires shouldComponentUpdate function where socketSignal prop is present
// setting socketSignal to null immediately after to avoid multiple database fetches
getSocketSignal = type => {
console.log(type);
this.setState(
{
socketSignal: type
},
() => {
this.setState({
socketSignal: null
});
}
);
};
handleState = data => { handleState = data => {
sessionStorage.setItem("name", data.name); sessionStorage.setItem("name", data.name);
sessionStorage.setItem("token", data.token); sessionStorage.setItem("token", data.token);
...@@ -148,13 +132,6 @@ export default class App extends Component { ...@@ -148,13 +132,6 @@ export default class App extends Component {
return ( return (
<div> <div>
{this.state.currentGameId && (
<ClientSocket
gameId={this.state.currentGameId}
getSocketSignal={this.getSocketSignal}
/>
)}
<Router> <Router>
<div> <div>
{/* Debug Sign out button ------------------------ */} {/* Debug Sign out button ------------------------ */}
......
...@@ -7,6 +7,7 @@ import JoinGameForm from "./JoinGameForm"; ...@@ -7,6 +7,7 @@ import JoinGameForm from "./JoinGameForm";
import PlayerlistView from "./PlayerlistView"; import PlayerlistView from "./PlayerlistView";
import NotificationView from "./NotificationView"; import NotificationView from "./NotificationView";
import GameStateButtons from "./GameStateButtons"; import GameStateButtons from "./GameStateButtons";
import ClientSocket from "./Socket";
export default class GameView extends React.Component { export default class GameView extends React.Component {
state = { state = {
...@@ -16,7 +17,8 @@ export default class GameView extends React.Component { ...@@ -16,7 +17,8 @@ export default class GameView extends React.Component {
lat: 62.2416479, lat: 62.2416479,
lng: 25.7597186, lng: 25.7597186,
zoom: 13, zoom: 13,
mapUrl: "https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg" mapUrl: "https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg",
socketSignal: null
}; };
componentDidMount() { componentDidMount() {
...@@ -84,6 +86,22 @@ export default class GameView extends React.Component { ...@@ -84,6 +86,22 @@ export default class GameView extends React.Component {
.catch(error => console.log(error)); .catch(error => console.log(error));
}; };
// setting the socket signal automatically fires shouldComponentUpdate function where socketSignal prop is present
// setting socketSignal to null immediately after to avoid multiple database fetches
getSocketSignal = type => {
console.log(type);
this.setState(
{
socketSignal: type
},
() => {
this.setState({
socketSignal: null
});
}
);
};
render() { render() {
const initialPosition = [this.state.lat, this.state.lng]; const initialPosition = [this.state.lat, this.state.lng];
...@@ -94,6 +112,12 @@ export default class GameView extends React.Component { ...@@ -94,6 +112,12 @@ export default class GameView extends React.Component {
</Link> </Link>
{this.state.gameInfo !== null && ( {this.state.gameInfo !== null && (
<div> <div>
{this.state.gameInfo.id && (
<ClientSocket
gameId={this.state.gameInfo.id}
getSocketSignal={this.getSocketSignal}
/>
)}
<div>Game Name: {this.state.gameInfo.name}</div> <div>Game Name: {this.state.gameInfo.name}</div>
{this.state.role === "" && ( {this.state.role === "" && (
<div>You don't have a role in this game</div> <div>You don't have a role in this game</div>
...@@ -153,6 +177,7 @@ export default class GameView extends React.Component { ...@@ -153,6 +177,7 @@ export default class GameView extends React.Component {
zoom={this.state.zoom} zoom={this.state.zoom}
mapUrl={this.state.mapUrl} mapUrl={this.state.mapUrl}
currentGameId={this.state.gameInfo.id} currentGameId={this.state.gameInfo.id}
socketSignal={this.state.socketSignal}
/> />
{this.state.form === "edit" && ( {this.state.form === "edit" && (
<EditGameForm <EditGameForm
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment