From 4a2f70b8e7c534276fc77500488894d07116c492 Mon Sep 17 00:00:00 2001 From: "matis.mazingue" Date: Sat, 29 Jun 2024 11:57:36 +0200 Subject: [PATCH] delete recipe in order when recipe is delete --- src/app/home/home.component.ts | 5 ++++- src/app/services/recipe.service.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index afcc3ff..36276de 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -16,7 +16,10 @@ export class HomeComponent implements OnInit { constructor(private recipeService: RecipeService) {} ngOnInit(): void { - // Charger les commandes en cours depuis le service + this.loadCurrentOrders(); + } + + loadCurrentOrders(): void { this.currentOrders = this.recipeService.getCurrentOrders(); } } diff --git a/src/app/services/recipe.service.ts b/src/app/services/recipe.service.ts index 55c562e..7b6c872 100644 --- a/src/app/services/recipe.service.ts +++ b/src/app/services/recipe.service.ts @@ -26,14 +26,18 @@ export class RecipeService { 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 + // Supprimer les IngredientRecipe associés let ingredientRecipes = this.getIngredientRecipes(recipeId); ingredientRecipes = ingredientRecipes.filter(ir => ir.idRecipe !== recipeId); localStorage.setItem(this.ingredientRecipeKey, JSON.stringify(ingredientRecipes)); + + // Mettre à jour les commandes en cours + let currentOrders = this.getCurrentOrders(); + currentOrders = currentOrders.filter(order => order.id !== recipeId); + localStorage.setItem(this.currentOrdersKey, JSON.stringify(currentOrders)); } }