|
@@ -17,7 +17,8 @@ class App extends Component {
|
|
|
|
|
|
// is called once when loading the page
|
|
// is called once when loading the page
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
- fetch("http://192.168.8.100:3001/persons")
|
|
|
|
|
|
+ //fetch("http://192.168.8.100:3001/persons")
|
|
|
|
+ fetch("http://localhost:5000/users")
|
|
.then(response => {
|
|
.then(response => {
|
|
if (response.ok) {
|
|
if (response.ok) {
|
|
return response;
|
|
return response;
|
|
@@ -29,8 +30,8 @@ class App extends Component {
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(response => response.json())
|
|
.then(json =>{
|
|
.then(json =>{
|
|
- console.log(json);
|
|
|
|
- this.setState({ persons: json })
|
|
|
|
|
|
+ console.log(json["users"]);
|
|
|
|
+ this.setState({ persons: json["users"] })
|
|
}).catch(error => {
|
|
}).catch(error => {
|
|
console.log(error);
|
|
console.log(error);
|
|
});
|
|
});
|
|
@@ -38,7 +39,7 @@ class App extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- change = () => {
|
|
|
|
|
|
+ /*change = () => {
|
|
const newPersons = [...this.state.persons];
|
|
const newPersons = [...this.state.persons];
|
|
const id = 0;
|
|
const id = 0;
|
|
newPersons.map( person => {
|
|
newPersons.map( person => {
|
|
@@ -47,7 +48,8 @@ class App extends Component {
|
|
let longitude = Math.floor((Math.random() * 150) + 1);
|
|
let longitude = Math.floor((Math.random() * 150) + 1);
|
|
let latitude = Math.floor((Math.random() * 150) + 1);
|
|
let latitude = Math.floor((Math.random() * 150) + 1);
|
|
|
|
|
|
- axios.put('http://192.168.8.100:3001/persons/0/', {
|
|
|
|
|
|
+ //axios.put('http://192.168.8.100:3001/persons/0/', {
|
|
|
|
+ axios.put('http://localhost:3001/persons/0/', {
|
|
longitude: longitude,
|
|
longitude: longitude,
|
|
latitude: latitude,
|
|
latitude: latitude,
|
|
shortName: "VEN",
|
|
shortName: "VEN",
|
|
@@ -62,14 +64,25 @@ class App extends Component {
|
|
})
|
|
})
|
|
this.componentDidMount()
|
|
this.componentDidMount()
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
getLocation = (name) => {
|
|
getLocation = (name) => {
|
|
|
|
+ const axios = require('axios');
|
|
const newPersons = [...this.state.persons];
|
|
const newPersons = [...this.state.persons];
|
|
|
|
|
|
if (navigator.geolocation) { //check if geolocation is available
|
|
if (navigator.geolocation) { //check if geolocation is available
|
|
navigator.geolocation.getCurrentPosition(function(position){
|
|
navigator.geolocation.getCurrentPosition(function(position){
|
|
console.log(position);
|
|
console.log(position);
|
|
|
|
+ console.log({"longitude": position.coords.longitude, "latitude": position.coords.latitude, "timestamp": position.timestamp, "name": name})
|
|
|
|
+
|
|
|
|
+ axios.put('http://localhost:5000/report-location', {
|
|
|
|
+ "longitude": position.coords.longitude,
|
|
|
|
+ "latitude": position.coords.latitude,
|
|
|
|
+ "timestamp": position.timestamp,
|
|
|
|
+ "name": name}).catch(error => {
|
|
|
|
+ console.log(error);
|
|
|
|
+ });
|
|
|
|
+
|
|
newPersons.map( person => {
|
|
newPersons.map( person => {
|
|
if (name == person.name) {
|
|
if (name == person.name) {
|
|
person.longitude = position.coords.longitude
|
|
person.longitude = position.coords.longitude
|
|
@@ -82,11 +95,9 @@ class App extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- getAttribute = (id, attr) => {
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
- create = (id) => {
|
|
|
|
|
|
+ /*create = (id) => {
|
|
const axios = require('axios');
|
|
const axios = require('axios');
|
|
let longitude = Math.floor((Math.random() * 100) + 1);
|
|
let longitude = Math.floor((Math.random() * 100) + 1);
|
|
let latitude = Math.floor((Math.random() * 100) + 1);
|
|
let latitude = Math.floor((Math.random() * 100) + 1);
|
|
@@ -100,6 +111,7 @@ class App extends Component {
|
|
})
|
|
})
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ //axios.put('http://localhost:3001/persons/0/', {
|
|
axios.put('http://localhost:3001/persons/0/', {
|
|
axios.put('http://localhost:3001/persons/0/', {
|
|
longitude: longitude,
|
|
longitude: longitude,
|
|
latitude: latitude,
|
|
latitude: latitude,
|
|
@@ -110,10 +122,10 @@ class App extends Component {
|
|
}).catch(error => {
|
|
}).catch(error => {
|
|
console.log(error);
|
|
console.log(error);
|
|
});
|
|
});
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
render (){
|
|
render (){
|
|
- setTimeout(this.componentDidMount, 10000)
|
|
|
|
|
|
+ //setTimeout(this.componentDidMount, 10000)
|
|
|
|
|
|
return (
|
|
return (
|
|
<div id="wrapper">
|
|
<div id="wrapper">
|
|
@@ -121,12 +133,12 @@ class App extends Component {
|
|
<div id="debug"> </div>
|
|
<div id="debug"> </div>
|
|
<button
|
|
<button
|
|
onClick={ () => {
|
|
onClick={ () => {
|
|
- alert(this.getAttribute(2, "name"));
|
|
|
|
|
|
+ this.getLocation("Bernie");
|
|
}}
|
|
}}
|
|
> Bernie </button>
|
|
> Bernie </button>
|
|
<button
|
|
<button
|
|
onClick={ () => {
|
|
onClick={ () => {
|
|
- this.change();
|
|
|
|
|
|
+ this.getLocation("Martin");
|
|
}}
|
|
}}
|
|
> Martin </button>
|
|
> Martin </button>
|
|
<button
|
|
<button
|