master
Hugo PRADIER 10 months ago
commit 610ce4e707

@ -23,6 +23,10 @@ export class HomeComponent implements OnInit {
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
this.loadCurrentOrders();
}
loadCurrentOrders(): void {
this.currentOrders = this.recipeService.getCurrentOrders(); this.currentOrders = this.recipeService.getCurrentOrders();
this.isLoggedIn = this.authService.isLoggedIn(); this.isLoggedIn = this.authService.isLoggedIn();
} }

@ -29,6 +29,7 @@ export class RecipeService {
recipes = recipes.filter((recipe) => recipe.id !== recipeId); recipes = recipes.filter((recipe) => recipe.id !== recipeId);
localStorage.setItem(this.localStorageKey, JSON.stringify(recipes)); localStorage.setItem(this.localStorageKey, JSON.stringify(recipes));
// Supprimer les IngredientRecipe associés
let ingredientRecipes = this.getIngredientRecipes(recipeId); let ingredientRecipes = this.getIngredientRecipes(recipeId);
ingredientRecipes = ingredientRecipes.filter( ingredientRecipes = ingredientRecipes.filter(
(ir) => ir.idRecipe !== recipeId (ir) => ir.idRecipe !== recipeId
@ -37,6 +38,14 @@ export class RecipeService {
this.ingredientRecipeKey, this.ingredientRecipeKey,
JSON.stringify(ingredientRecipes) 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