diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 5880e5f..5511aa4 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -23,6 +23,10 @@ export class HomeComponent implements OnInit { ) {} ngOnInit(): void { + this.loadCurrentOrders(); + } + + loadCurrentOrders(): void { this.currentOrders = this.recipeService.getCurrentOrders(); this.isLoggedIn = this.authService.isLoggedIn(); } diff --git a/src/app/services/recipe.service.ts b/src/app/services/recipe.service.ts index 6a2a474..b6e8231 100644 --- a/src/app/services/recipe.service.ts +++ b/src/app/services/recipe.service.ts @@ -29,6 +29,7 @@ export class RecipeService { recipes = recipes.filter((recipe) => recipe.id !== recipeId); localStorage.setItem(this.localStorageKey, JSON.stringify(recipes)); + // Supprimer les IngredientRecipe associés let ingredientRecipes = this.getIngredientRecipes(recipeId); ingredientRecipes = ingredientRecipes.filter( (ir) => ir.idRecipe !== recipeId @@ -37,6 +38,14 @@ export class RecipeService { 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) + ); } }