diff --git a/src/components/EditRecipePage.vue b/src/components/EditRecipePage.vue index d967035..abc8ac0 100644 --- a/src/components/EditRecipePage.vue +++ b/src/components/EditRecipePage.vue @@ -12,7 +12,7 @@
@@ -173,6 +176,12 @@ export default { }, addIngredient() { this.recipe.ingredients.push({ line: '', product: null }); + }, + async deleteRecipe() { + if (confirm('Are you sure you want to delete this recipe?')) { + await data.deleteRecipe(this.recipe.id); + this.$router.push('/'); + } } }, } diff --git a/src/data.js b/src/data.js index 1f97d9c..b61d884 100644 --- a/src/data.js +++ b/src/data.js @@ -115,5 +115,11 @@ export default { user = await response.json(); return user; + }, + async deleteRecipe(id) { + var response = await fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`, { + method: "DELETE", + }); + return await response.json(); } } \ No newline at end of file