Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-frontend
Commits
edd726cc
Commit
edd726cc
authored
5 years ago
by
L4929
Browse files
Options
Downloads
Patches
Plain Diff
Moved ClientSocket to GameView.js, along with getSocketSignal function and socketSignal state
parent
b031a9c9
No related branches found
Branches containing commit
No related tags found
2 merge requests
!31
Development
,
!29
Fixed socket functionality
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/App.js
+0
-23
0 additions, 23 deletions
src/App.js
src/components/GameView.js
+26
-1
26 additions, 1 deletion
src/components/GameView.js
with
26 additions
and
24 deletions
src/App.js
+
0
−
23
View file @
edd726cc
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 ------------------------ */
}
...
...
This diff is collapsed.
Click to expand it.
src/components/GameView.js
+
26
−
1
View file @
edd726cc
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment