|
|
|
@ -22,8 +22,18 @@ export class RecipeService {
|
|
|
|
|
|
|
|
|
|
deleteRecipe(recipeId: number): void {
|
|
|
|
|
let recipes = this.getRecipes();
|
|
|
|
|
const deletedRecipe = recipes.find(recipe => recipe.id === recipeId);
|
|
|
|
|
|
|
|
|
|
if (deletedRecipe) {
|
|
|
|
|
// Remove the recipe from recipes array
|
|
|
|
|
recipes = recipes.filter(recipe => recipe.id !== recipeId);
|
|
|
|
|
localStorage.setItem(this.localStorageKey, JSON.stringify(recipes));
|
|
|
|
|
|
|
|
|
|
// Remove associated IngredientRecipe objects
|
|
|
|
|
let ingredientRecipes = this.getIngredientRecipes(recipeId);
|
|
|
|
|
ingredientRecipes = ingredientRecipes.filter(ir => ir.idRecipe !== recipeId);
|
|
|
|
|
localStorage.setItem(this.ingredientRecipeKey, JSON.stringify(ingredientRecipes));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getIngredientRecipes(recipeId: number): IngredientRecipe[] {
|
|
|
|
|