implemented attribute type to differentiate between comments and posts while using the same component for both types

This commit is contained in:
Pete Gerlach
2024-06-11 15:50:43 +02:00
parent f17b253ac6
commit 905e259af2
4 changed files with 62 additions and 34 deletions

View File

@@ -10,19 +10,33 @@ export const postApi = {
async getPostByID (id) {
return (await axios.get(`${path}/${id}`)).data;
},
async createNewPost(title, content) {
async createNewPost(title, content, parent = null) {
const location = await 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,
},
});
if(parent !== null) {
await axios.post(`${path}s`, {
"authorID": 1,
"title": title,
"content": content,
"date": Date.now().toString(),
"location": {
"longitude": location.lon,
"latitude": location.lat,
},
"parent": parent
});
} else {
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");
}