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
7a7c5e27
Commit
7a7c5e27
authored
5 years ago
by
Ronnie Friman
Browse files
Options
Downloads
Patches
Plain Diff
reworked fetch functions
parent
2a0e7689
No related branches found
Branches containing commit
No related tags found
2 merge requests
!46
Development to testing
,
!34
Filter player replay
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/ReplayMap.js
+27
-32
27 additions, 32 deletions
src/components/ReplayMap.js
with
27 additions
and
32 deletions
src/components/ReplayMap.js
+
27
−
32
View file @
7a7c5e27
...
@@ -3,12 +3,10 @@
...
@@ -3,12 +3,10 @@
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
{
Link
}
from
"
react-router-dom
"
;
import
L
from
"
leaflet
"
;
import
L
from
"
leaflet
"
;
import
{
Map
,
TileLayer
,
ZoomControl
,
Marker
,
Popup
}
from
"
react-leaflet
"
;
import
"
../track-playback/src/leaflet.trackplayback/clock
"
;
import
"
../track-playback/src/leaflet.trackplayback/clock
"
;
import
"
../track-playback/src/leaflet.trackplayback/index
"
;
import
"
../track-playback/src/leaflet.trackplayback/index
"
;
import
"
../track-playback/src/control.trackplayback/control.playback
"
;
import
"
../track-playback/src/control.trackplayback/control.playback
"
;
import
"
../track-playback/src/control.trackplayback/index
"
;
import
"
../track-playback/src/control.trackplayback/index
"
;
import
DrawGeoJSON
from
"
./DrawGeoJSON
"
;
export
default
class
ReplayMap
extends
React
.
Component
{
export
default
class
ReplayMap
extends
React
.
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
...
@@ -23,30 +21,38 @@ export default class ReplayMap extends React.Component {
...
@@ -23,30 +21,38 @@ export default class ReplayMap extends React.Component {
// stores all active drawings on the map
// stores all active drawings on the map
activeGeoJSON
:
[]
activeGeoJSON
:
[]
};
};
this
.
map
=
React
.
createRef
();
}
}
async
componentDidMount
()
{
async
componentDidMount
()
{
// set gameId to state from URL
await
this
.
setState
({
await
this
.
setState
({
gameId
:
await
new
URL
(
window
.
location
.
href
).
searchParams
.
get
(
"
id
"
)
gameId
:
await
new
URL
(
window
.
location
.
href
).
searchParams
.
get
(
"
id
"
)
});
});
await
this
.
fetchPlayerData
();
// fetch player data with gameId
//await this.fetchDrawingData();
// throws error if game is not found and redirects back to game selection
//this.tickDrawings();
await
this
.
setState
({
data
:
await
this
.
fetchPlayerData
()
});
// fetch drawings with gameId
await
this
.
setState
({
allGeoJSON
:
await
this
.
fetchDrawingData
()
});
// WIP, map only active drawings to activeGeoJSON state
await
this
.
setState
({
activeGeoJSON
:
this
.
tickDrawings
()
});
// if game was found but game has no replay data, alert the user
this
.
state
.
data
.
length
>
1
this
.
state
.
data
.
length
>
1
?
this
.
replay
()
?
this
.
replay
()
:
alert
(
"
No replay data was found
"
);
:
alert
(
"
No replay data was found
"
);
}
}
componentWillReceiveProps
(
nextProps
)
{}
fetchPlayerData
=
async
()
=>
{
fetchPlayerData
=
async
()
=>
{
let
res
=
await
fetch
(
let
res
=
await
fetch
(
`
${
process
.
env
.
REACT_APP_API_URL
}
/replay/players/
${
this
.
state
.
gameId
}
`
`
${
process
.
env
.
REACT_APP_API_URL
}
/replay/players/
${
this
.
state
.
gameId
}
`
);
);
if
(
await
res
.
ok
)
{
if
(
res
.
ok
)
{
return
await
res
.
json
();
await
this
.
setState
({
data
:
res
.
json
()
});
}
else
{
}
else
{
alert
(
"
Game not found
"
);
alert
(
"
Game not found
"
);
window
.
document
.
location
.
href
=
"
/
"
;
window
.
document
.
location
.
href
=
"
/
"
;
...
@@ -54,30 +60,19 @@ export default class ReplayMap extends React.Component {
...
@@ -54,30 +60,19 @@ export default class ReplayMap extends React.Component {
};
};
fetchDrawingData
=
async
()
=>
{
fetchDrawingData
=
async
()
=>
{
await
fetch
(
`
${
process
.
env
.
REACT_APP_API_URL
}
/replay/
${
this
.
gameId
}
`
,
{
let
res
=
await
fetch
(
method
:
"
GET
"
`
${
process
.
env
.
REACT_APP_API_URL
}
/replay/
${
this
.
state
.
gameId
}
`
})
);
.
then
(
async
res
=>
await
res
.
json
())
if
(
await
res
.
ok
)
{
.
then
(
return
await
res
.
json
();
async
res
=>
{
}
else
{
await
this
.
setState
({
allGeoJSON
:
res
});
alert
(
res
.
statusText
);
},
}
error
=>
{
console
.
log
(
error
);
}
);
};
};
tickDrawings
=
()
=>
{
tickDrawings
=
()
=>
{
let
activeDrawings
=
[];
return
this
.
state
.
allGeoJSON
.
map
(
drawing
=>
{
this
.
state
.
allGeoJSON
.
map
(
drawing
=>
{
return
drawing
[
0
];
activeDrawings
.
push
(
drawing
[
0
]);
this
.
setState
({
activeGeoJSON
:
{
type
:
"
FeatureCollection
"
,
features
:
[...
activeDrawings
]
}
});
});
});
};
};
...
...
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