Skip to content
Snippets Groups Projects
Commit 2a0e7689 authored by Ronnie Friman's avatar Ronnie Friman
Browse files

get gameId from url

parent 7caaa498
No related branches found
No related tags found
2 merge requests!46Development to testing,!34Filter player replay
// https://github.com/linghuam/Leaflet.TrackPlayBack // https://github.com/linghuam/Leaflet.TrackPlayBack
import React from "react"; import React from "react";
import { Link } from "react-router-dom";
import L from "leaflet"; import L from "leaflet";
import { Map, TileLayer, ZoomControl, Marker, Popup } from "react-leaflet"; import { Map, TileLayer, ZoomControl, Marker, Popup } from "react-leaflet";
import "../track-playback/src/leaflet.trackplayback/clock"; import "../track-playback/src/leaflet.trackplayback/clock";
...@@ -26,51 +27,36 @@ export default class ReplayMap extends React.Component { ...@@ -26,51 +27,36 @@ export default class ReplayMap extends React.Component {
} }
async componentDidMount() { async componentDidMount() {
await this.setState({
gameId: await new URL(window.location.href).searchParams.get("id")
});
await this.fetchPlayerData(); await this.fetchPlayerData();
//await this.fetchDrawingData(); //await this.fetchDrawingData();
//this.tickDrawings(); //this.tickDrawings();
this.replay(); this.state.data.length > 1
? this.replay()
: alert("No replay data was found");
} }
componentWillReceiveProps(nextProps) {} componentWillReceiveProps(nextProps) {}
// cloud game a1231e2b-aa29-494d-b687-ea2d48cc23df
// local game wimma 314338f9-b0bb-4bf7-9554-769c7b409bce
// local game vbox 16977b13-c419-48b4-b7d6-e7620f27bf39
// fetch player locations from the game
fetchPlayerData = async () => { fetchPlayerData = async () => {
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/314338f9-b0bb-4bf7-9554-769c7b409bce`,
{ if (res.ok) {
method: "GET" await this.setState({ data: res.json() });
} } else {
) alert("Game not found");
.then(async res => await res.json()) window.document.location.href = "/";
.then( }
async res => {
await this.setState({ data: res });
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
error => {
console.log(error);
}
);
}; };
fetchDrawingData = async () => { fetchDrawingData = async () => {
await fetch( await fetch(`${process.env.REACT_APP_API_URL}/replay/${this.gameId}`, {
`${process.env.REACT_APP_API_URL}/replay/{ method: "GET"
"lng": 25.72588, })
"lat": 62.23147
}`,
{
method: "GET"
}
)
.then(async res => await res.json()) .then(async res => await res.json())
.then( .then(
async res => { async res => {
...@@ -170,6 +156,9 @@ export default class ReplayMap extends React.Component { ...@@ -170,6 +156,9 @@ export default class ReplayMap extends React.Component {
)} )}
</Map> */ </Map> */
<React.Fragment> <React.Fragment>
<Link to="/">
<button>Game selection</button>
</Link>
<div className="map" ref="map" /> <div className="map" ref="map" />
</React.Fragment> </React.Fragment>
); );
......
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