Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
B
burger-builder-template
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нұрасыл Қайратұлы
burger-builder-template
Commits
6fbfdb79
Commit
6fbfdb79
authored
Dec 16, 2024
by
Нұрасыл Қайратұлы
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add order now
parent
eabf3027
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
3 deletions
+60
-3
BuildControls.css
src/components/BuildControls/BuildControls.css
+40
-0
BuildControls.tsx
src/components/BuildControls/BuildControls.tsx
+5
-2
BurgerBuilder.tsx
src/containers/BurgerBuilder/BurgerBuilder.tsx
+15
-1
No files found.
src/components/BuildControls/BuildControls.css
View file @
6fbfdb79
...
...
@@ -8,3 +8,43 @@
margin
:
auto
;
padding
:
10px
0
;
}
.OrderButton
{
background-color
:
#dad735
;
outline
:
none
;
cursor
:
pointer
;
border
:
1px
solid
#966909
;
color
:
#966909
;
font-family
:
inherit
;
font-size
:
1.2em
;
padding
:
15px
30px
;
box-shadow
:
2px
2px
2px
#966909
;
}
.OrderButton
:hover
,
.OrderButton
:active
{
background-color
:
#a0db41
;
border
:
1px
solid
#966909
;
color
:
#966909
;
}
.OrderButton
:disabled
{
background-color
:
#c7c6c6
;
cursor
:
not-allowed
;
border
:
1px
solid
#ccc
;
color
:
#888888
;
}
.OrderButton
:not
(
:disabled
)
{
animation
:
enable
0.3s
linear
;
}
@keyframes
enable
{
0
%
{
transform
:
scale
(
1
);
}
60
%
{
transform
:
scale
(
1.1
);
}
100
%
{
transform
:
scale
(
1
);
}
}
\ No newline at end of file
src/components/BuildControls/BuildControls.tsx
View file @
6fbfdb79
...
...
@@ -3,13 +3,14 @@ import BuildControl from './BuildControl/BuildControl';
import
'./BuildControls.css'
;
interface
Props
{
ingredients
:
Ingredients
price
:
number
purchasable
:
boolean
ingredients
:
Ingredients
lessHandler
:
(
ingKey
:
IngredientNames
)
=>
void
moreHandler
:
(
ingKey
:
IngredientNames
)
=>
void
}
const
BuildControls
=
({
ingredients
,
price
,
lessHandler
,
moreHandler
}:
Props
)
=>
{
const
BuildControls
=
({
ingredients
,
p
urchasable
,
p
rice
,
lessHandler
,
moreHandler
}:
Props
)
=>
{
const
ingKeys
=
Object
.
keys
(
ingredients
)
return
(
...
...
@@ -27,6 +28,8 @@ const BuildControls = ({ingredients, price, lessHandler, moreHandler}: Props) =>
/>
))
}
<
button
className=
"OrderButton"
disabled=
{
!
purchasable
}
>
ORDER NOW
</
button
>
</
div
>
);
}
...
...
src/containers/BurgerBuilder/BurgerBuilder.tsx
View file @
6fbfdb79
...
...
@@ -5,12 +5,21 @@ import { useState } from 'react';
const
BurgerBuilder
=
()
=>
{
const
[
totalPrice
,
setTotalPrice
]
=
useState
<
number
>
(
IngredientPrices
.
bread
);
const
[
purchasable
,
setPurchasable
]
=
useState
<
boolean
>
(
false
);
const
[
ingredients
,
setIngredients
]
=
useState
<
Ingredients
>
({
salad
:
0
,
cheese
:
0
,
chicken
:
0
,
meat
:
0
})
});
const
updatePurschasable
=
(
ingredients
:
Ingredients
)
=>
{
const
sum
=
Object
.
keys
(
ingredients
)
.
map
(
ingKey
=>
ingredients
[
ingKey
as
IngredientNames
])
.
reduce
((
sum
,
el
)
=>
sum
+
el
,
0
)
setPurchasable
(
sum
>
0
)
}
const
moreHandler
=
(
ingKey
:
IngredientNames
)
=>
{
const
oldCount
=
ingredients
[
ingKey
];
...
...
@@ -22,6 +31,8 @@ const BurgerBuilder = () => {
const
priceAddition
=
IngredientPrices
[
ingKey
];
const
newPrice
=
totalPrice
+
priceAddition
;
setTotalPrice
(
newPrice
);
updatePurschasable
(
updatedIngredients
);
}
const
lessHandler
=
(
ingKey
:
IngredientNames
)
=>
{
...
...
@@ -38,6 +49,8 @@ const BurgerBuilder = () => {
const
priceAddition
=
IngredientPrices
[
ingKey
];
const
newPrice
=
totalPrice
-
priceAddition
;
setTotalPrice
(
newPrice
);
updatePurschasable
(
updatedIngredients
);
}
return
(
...
...
@@ -48,6 +61,7 @@ const BurgerBuilder = () => {
lessHandler=
{
lessHandler
}
moreHandler=
{
moreHandler
}
price=
{
totalPrice
}
purchasable=
{
purchasable
}
/>
</>
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment