Add ability to delete (hide) recipes
This commit is contained in:
parent
61ec004360
commit
52b7059827
2 changed files with 17 additions and 2 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
<div v-if="!parse_failed && recipe">
|
<div v-if="!parse_failed && recipe">
|
||||||
<div class="image-container" v-if="image_styling" :style="image_styling" ></div>
|
<div class="image-container" v-if="image_styling" :style="image_styling" ></div>
|
||||||
<h1><input class="recipe-name" type="text" :value="recipe.name"></h1>
|
<h1><input class="recipe-name" type="text" v-model="recipe.name" /></h1>
|
||||||
<h3 class="recipe-link"><a :href="recipe.link">View Recipe</a></h3>
|
<h3 class="recipe-link"><a :href="recipe.link">View Recipe</a></h3>
|
||||||
<h2>Ingredients</h2>
|
<h2>Ingredients</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
@ -29,7 +29,10 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<button @click="addIngredient">Add Ingredient</button>
|
<button @click="addIngredient">Add Ingredient</button>
|
||||||
<button class="submit-btn" @click="saveRecipe">Save</button>
|
<div>
|
||||||
|
<button v-if="recipe.id" class="delete-btn" @click="deleteRecipe">Delete</button>
|
||||||
|
<button class="submit-btn" @click="saveRecipe">{{ recipe.id ? "Save" : "Create" }}</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -173,6 +176,12 @@ export default {
|
||||||
},
|
},
|
||||||
addIngredient() {
|
addIngredient() {
|
||||||
this.recipe.ingredients.push({ line: '', product: null });
|
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('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,5 +115,11 @@ export default {
|
||||||
|
|
||||||
user = await response.json();
|
user = await response.json();
|
||||||
return user;
|
return user;
|
||||||
|
},
|
||||||
|
async deleteRecipe(id) {
|
||||||
|
var response = await fetch(BASE_URL + `/recipes/${encodeURIComponent(id)}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
return await response.json();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue