exported getLocation function for reusability
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axios from "axios"
|
||||
import {locationUtils} from "../utils/location";
|
||||
|
||||
const path = "https://api.jodel.anxietyprime.de/post";
|
||||
|
||||
@@ -10,20 +11,17 @@ export const postApi = {
|
||||
return (await axios.get(`${path}/${id}`)).data;
|
||||
},
|
||||
async createNewPost(title, content) {
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(async function(position) {
|
||||
const latitude = position.coords.latitude;
|
||||
const longitude = position.coords.longitude;
|
||||
await axios.post(`${path}s`, {
|
||||
"authorID": 1,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"date": Date.now().toString(),
|
||||
"location": {
|
||||
"longitude": longitude,
|
||||
"latitude": latitude,
|
||||
},
|
||||
});
|
||||
const location = locationUtils.getCurrentLocation();
|
||||
if(location.lon && location.lat) {
|
||||
await axios.post(`${path}s`, {
|
||||
"authorID": 1,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"date": Date.now().toString(),
|
||||
"location": {
|
||||
"longitude": location.lon,
|
||||
"latitude": location.lat,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log("Geolocation is not supported by this browser. Could'nt post without valid location");
|
||||
|
||||
Reference in New Issue
Block a user