order recipe

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

@ -1,5 +1,11 @@
<div>
<h1>Projet Recipe</h1>
<br />
<h2>Commandes en cours</h2>
<ul>
<li *ngFor="let recipe of currentOrders">
{{ recipe.name }}
</li>
</ul>
<p>Bienvenue sur Recipe</p>
</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({
selector: 'app-home',
standalone: true,
imports: [],
imports: [CommonModule],
templateUrl: './home.component.html',
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">
<th mat-header-cell *matHeaderCellDef>Show</th>
<td mat-cell *matCellDef="let recipe">
<button mat-button color="accent" (click)="onOrderRecipe(recipe)">
Order
</button>
<button mat-button color="accent" (click)="onSelectRecipe(recipe)">
Show
</button>

@ -52,4 +52,8 @@ export class RecipeListComponent implements OnInit {
this.recipes = this.recipeService.getRecipes();
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 {
private localStorageKey = 'recipes';
private ingredientRecipeKey = 'ingredientRecipes';
private currentOrdersKey = 'currentOrders';
getRecipes(): Recipe[] {
const recipesJson = localStorage.getItem(this.localStorageKey);
@ -55,4 +56,15 @@ export class RecipeService {
);
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