From 52b705982722b43a3edd38228c3312f34a46e6d3 Mon Sep 17 00:00:00 2001 From: jableader Date: Sat, 4 May 2024 12:24:22 +1000 Subject: [PATCH] Add ability to delete (hide) recipes --- src/components/EditRecipePage.vue | 13 +++++++++++-- src/data.js | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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 @@
-

+

Ingredients

- +
+ + +
@@ -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