Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
web-system-2-final-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lirong xu
web-system-2-final-project
Commits
3c5b211e
Commit
3c5b211e
authored
1 year ago
by
xulirong2000
Browse files
Options
Downloads
Patches
Plain Diff
cart
parent
57926ba4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/pages/cart/cart-item.js
+28
-0
28 additions, 0 deletions
src/pages/cart/cart-item.js
src/pages/cart/cart.css
+44
-0
44 additions, 0 deletions
src/pages/cart/cart.css
src/pages/cart/cart.js
+19
-0
19 additions, 0 deletions
src/pages/cart/cart.js
with
91 additions
and
0 deletions
src/pages/cart/cart-item.js
+
28
−
0
View file @
3c5b211e
import
React
,
{
useContext
}
from
"
react
"
;
import
{
ShopContext
}
from
"
../../context/shop-context
"
;
export
const
CartItem
=
(
props
)
=>
{
const
{
id
,
productName
,
price
,
productImage
}
=
props
.
data
;
const
{
cartItems
,
addToCart
,
removeFromCart
,
updateCartItemCount
}
=
useContext
(
ShopContext
);
return
(
<
div
className
=
"
cartItem
"
>
<
img
src
=
{
productImage
}
/
>
<
div
className
=
"
description
"
>
<
p
>
<
b
>
{
productName
}
<
/b
>
<
/p
>
<
p
>
Price
:
$
{
price
}
<
/p
>
<
div
className
=
"
countHandler
"
>
<
button
onClick
=
{()
=>
removeFromCart
(
id
)}
>
-
<
/button
>
<
input
value
=
{
cartItems
[
id
]}
onChange
=
{(
e
)
=>
updateCartItemCount
(
Number
(
e
.
target
.
value
),
id
)}
/
>
<
button
onClick
=
{()
=>
addToCart
(
id
)}
>
+
<
/button
>
<
/div
>
<
/div
>
<
/div
>
);
};
This diff is collapsed.
Click to expand it.
src/pages/cart/cart.css
+
44
−
0
View file @
3c5b211e
.cart
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
.cartItem
{
width
:
700px
;
height
:
250px
;
display
:
flex
;
align-items
:
center
;
box-shadow
:
0px
3px
15px
rgba
(
0
,
0
,
0
,
0.2
);
border-radius
:
25px
;
margin
:
30px
;
}
.cartItem
img
{
width
:
200px
;
}
.cartItem
.description
{
width
:
100%
;
font-size
:
30px
;
}
.countHandler
input
{
width
:
40px
;
text-align
:
center
;
font-weight
:
bolder
;
}
.checkout
button
{
width
:
150px
;
height
:
50px
;
background-color
:
rgb
(
19
,
19
,
19
);
color
:
white
;
border
:
none
;
border-radius
:
8px
;
margin
:
10px
;
cursor
:
pointer
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/pages/cart/cart.js
+
19
−
0
View file @
3c5b211e
...
@@ -7,6 +7,8 @@ import { useNavigate } from "react-router-dom";
...
@@ -7,6 +7,8 @@ import { useNavigate } from "react-router-dom";
import
"
./cart.css
"
;
import
"
./cart.css
"
;
export
const
Cart
=
()
=>
{
export
const
Cart
=
()
=>
{
const
{
cartItems
,
getTotalCartAmount
,
checkout
}
=
useContext
(
ShopContext
);
const
{
cartItems
,
getTotalCartAmount
,
checkout
}
=
useContext
(
ShopContext
);
const
totalAmount
=
getTotalCartAmount
();
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
return
(
return
(
...
@@ -22,6 +24,23 @@ export const Cart = () => {
...
@@ -22,6 +24,23 @@ export const Cart = () => {
})}
})}
<
/div
>
<
/div
>
{
totalAmount
>
0
?
(
<
div
className
=
"
checkout
"
>
<
p
>
Subtotal
:
$
{
totalAmount
}
<
/p
>
<
button
onClick
=
{()
=>
navigate
(
"
/
"
)}
>
Continue
Shopping
<
/button
>
<
button
onClick
=
{()
=>
{
checkout
();
navigate
(
"
/checkout
"
);
}}
>
{
"
"
}
Checkout
{
"
"
}
<
/button
>
<
/div
>
)
:
(
<
h1
>
Your
Shopping
Cart
is
Empty
<
/h1
>
)}
<
/div
>
<
/div
>
);
);
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment