order recipe

master
Matis MAZINGUE 10 months ago
parent 475886ab96
commit 6f4d766328

@ -1,5 +1,11 @@
<div> <div>
<h1>Projet Recipe</h1> <h1>Projet Recipe</h1>
<br /> <br />
<h2>Commandes en cours</h2>
<ul>
<li *ngFor="let recipe of currentOrders">
{{ recipe.name }}
</li>
</ul>
<p>Bienvenue sur Recipe</p> <p>Bienvenue sur Recipe</p>
</div> </div>

@ -1,12 +1,22 @@
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Recipe } from '../models/recipe';
import { RecipeService } from '../services/recipe.service';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
standalone: true, standalone: true,
imports: [], imports: [CommonModule],
templateUrl: './home.component.html', templateUrl: './home.component.html',
styleUrl: './home.component.scss' styleUrl: './home.component.scss'
}) })
export class HomeComponent { export class HomeComponent implements OnInit {
currentOrders: Recipe[] = [];
constructor(private recipeService: RecipeService) {}
ngOnInit(): void {
// Charger les commandes en cours depuis le service
this.currentOrders = this.recipeService.getCurrentOrders();
}
} }

@ -42,6 +42,9 @@
<ng-container matColumnDef="actions"> <ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef>Show</th> <th mat-header-cell *matHeaderCellDef>Show</th>
<td mat-cell *matCellDef="let recipe"> <td mat-cell *matCellDef="let recipe">
<button mat-button color="accent" (click)="onOrderRecipe(recipe)">
Order
</button>
<button mat-button color="accent" (click)="onSelectRecipe(recipe)"> <button mat-button color="accent" (click)="onSelectRecipe(recipe)">
Show Show
</button> </button>

@ -52,4 +52,8 @@ export class RecipeListComponent implements OnInit {
this.recipes = this.recipeService.getRecipes(); this.recipes = this.recipeService.getRecipes();
this.dataSource.data = this.recipes; this.dataSource.data = this.recipes;
} }
onOrderRecipe(recipe: Recipe): void {
this.recipeService.orderRecipe(recipe);
}
} }

@ -8,6 +8,7 @@ import { IngredientRecipe } from '../models/ingredient-recipe';
export class RecipeService { export class RecipeService {
private localStorageKey = 'recipes'; private localStorageKey = 'recipes';
private ingredientRecipeKey = 'ingredientRecipes'; private ingredientRecipeKey = 'ingredientRecipes';
private currentOrdersKey = 'currentOrders';
getRecipes(): Recipe[] { getRecipes(): Recipe[] {
const recipesJson = localStorage.getItem(this.localStorageKey); const recipesJson = localStorage.getItem(this.localStorageKey);
@ -55,4 +56,15 @@ export class RecipeService {
); );
return ingredientRecipe ? ingredientRecipe.quantity : 0; return ingredientRecipe ? ingredientRecipe.quantity : 0;
} }
orderRecipe(recipe: Recipe): void {
let currentOrders: Recipe[] = JSON.parse(localStorage.getItem(this.currentOrdersKey) || '[]');
currentOrders.push(recipe);
localStorage.setItem(this.currentOrdersKey, JSON.stringify(currentOrders));
}
getCurrentOrders(): Recipe[] {
const currentOrdersJson = localStorage.getItem(this.currentOrdersKey);
return currentOrdersJson ? JSON.parse(currentOrdersJson) : [];
}
} }

Loading…
Cancel
Save