delete recipe in order when recipe is delete

master
Matis MAZINGUE 10 months ago
parent 710f0b2c10
commit 4a2f70b8e7

@ -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();
}
}

@ -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));
}
}

Loading…
Cancel
Save