Commit 5299eb97 authored by anton's avatar anton

first_lesson-4

parent 8ea89b32
......@@ -4,15 +4,17 @@ import { BuildControl } from "@/components/BuildControls/BuildControl/BuildContr
interface Props {
ingredients: Ingredients;
totalPrice: number;
hadlerLess: (key: IngredientNames) => void;
hadlerMore: (key: IngredientNames) => void;
}
export function BuildControls({ ingredients, hadlerLess, hadlerMore }: Props) {
export function BuildControls({ ingredients, totalPrice, hadlerLess, hadlerMore }: Props) {
const ingrKeys = Object.keys(ingredients) as (keyof Ingredients)[];
return (
<div className="BuildControls">
<p>Price: {totalPrice}</p>
{ingrKeys.map((key, i) => (
<BuildControl
key={key + i}
......
import { BuildControls } from "@/components/BuildControls/BuildControls";
import { Burger } from "@/components/Burger/Burger";
import { IngredientNames, Ingredients } from "@/interfaces/burger-interface";
import { IngredientNames, IngredientPrices, Ingredients } from "@/interfaces/burger-interface";
import { useState } from "react";
export function BurgerBuilder() {
const [totalPrice, setTotalPrice] = useState<number>(IngredientPrices.cheese);
const [ingredients, setIngredients] = useState<Ingredients>({
salad: 0,
cheese: 0,
......@@ -27,7 +28,12 @@ export function BurgerBuilder() {
return (
<>
<Burger ingredients={ingredients} />
<BuildControls ingredients={ingredients} hadlerLess={hadlerLess} hadlerMore={hadlerMore} />
<BuildControls
ingredients={ingredients}
hadlerLess={hadlerLess}
hadlerMore={hadlerMore}
totalPrice={totalPrice}
/>
</>
);
}
......@@ -3,3 +3,11 @@ export type IngredientNames = "salad" | "cheese" | "meat" | "bacon";
export type Ingredients = {
[key in IngredientNames]: number;
};
export enum IngredientPrices {
salad = 200,
cheese = 400,
bacon = 700,
meat = 900,
bread = 150,
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment