@@ -8,12 +8,13 @@ import { useCartProducts } from '../Domain/cartContext'
88import Image from 'next/image' ;
99import emptyCart from '../images/empty-cart.png'
1010import Link from 'next/link' ;
11+ import Loading from '../components/loading' ;
1112
1213export default function CartPage ( ) {
1314 const { isDarkMode } = useTheme ( ) ;
1415 const [ subTotal , setSubTotal ] = useState ( 0 )
1516 const [ showModal , setShowModal ] = useState ( false )
16- const { cartProducts } = useCartProducts ( ) ;
17+ const { cartProducts, cartLoading } = useCartProducts ( ) ;
1718
1819 useEffect ( ( ) => {
1920 let newSubtotal = 0
@@ -30,35 +31,37 @@ export default function CartPage() {
3031 < div className = 'h-24 w-[80vw] font-bold mt-16 flex flex-col items-center justify-center ' >
3132 < h1 className = 'text-3xl' > Shopping Cart</ h1 >
3233 </ div >
33- { cartProducts . length === 0 ?
34- < div className = 'flex flex-col items-center justify-center mt-10' >
35- < div className = 'h-40 w-40 rounded-full border-2 border-black flex items-center justify-center mb-4' >
36- < Image src = { emptyCart } width = { 100 } height = { 100 } alt = 'Empty Cart Image' />
37- </ div >
38- < h1 className = 'text-3xl font-bold mb-2' > Your Cart is currently empty</ h1 >
39- < p className = 'text-lg' > Looks Like you haven't add anything to your cart yet</ p >
40- < Link href = '/' className = ' hover:scale-110 mt-8 bg-ACMDARK w-44 h-10 flex items-center justify-center rounded-lg duration-200 transition-all ease-out' > Continue Shopping</ Link >
41- </ div >
42- : < >
43- < div >
44- { cartProducts && cartProducts . map ( ( product ) => {
45- return (
46- < CartProduct key = { product . id } product = { product } />
47- )
48- } ) }
49- </ div >
50- < div className = 'w-10/12 flex flex-col items-end ' >
51- < div className = { `w-60 flex justify-between flex-row text-xl font-bold mb-4 text-ACMDARK` } >
52- < h1 className = '' > SubTotal</ h1 >
53- < h1 > ${ subTotal } </ h1 >
34+ { cartLoading ? < Loading isRed = { false } /> : ( < >
35+ { cartProducts . length === 0 ?
36+ < div className = 'flex flex-col items-center justify-center mt-10' >
37+ < div className = 'h-40 w-40 rounded-full border-2 border-black flex items-center justify-center mb-4' >
38+ < Image src = { emptyCart } width = { 100 } height = { 100 } alt = 'Empty Cart Image' />
5439 </ div >
55- < button
56- onClick = { ( ) => setShowModal ( true ) }
57- className = 'hover:scale-110 text-lg duration-200 mb-10 transition-all ease-out bg-ACMDARK w-60 h-10 pt-1 pb-1 rounded-lg text-white' >
58- Checkout
59- </ button >
40+ < h1 className = 'text-3xl font-bold mb-2' > Your Cart is currently empty</ h1 >
41+ < p className = 'text-lg' > Looks Like you haven't add anything to your cart yet</ p >
42+ < Link href = '/' className = ' hover:scale-110 mt-8 bg-ACMDARK w-44 h-10 flex items-center justify-center rounded-lg duration-200 transition-all ease-out' > Continue Shopping</ Link >
6043 </ div >
61- </ > }
44+ : < >
45+ < div >
46+ { cartProducts && cartProducts . map ( ( product ) => {
47+ return (
48+ < CartProduct key = { product . id } product = { product } />
49+ )
50+ } ) }
51+ </ div >
52+ < div className = 'w-10/12 flex flex-col items-end ' >
53+ < div className = { `w-60 flex justify-between flex-row text-xl font-bold mb-4 text-ACMDARK` } >
54+ < h1 className = '' > SubTotal</ h1 >
55+ < h1 > ${ subTotal } </ h1 >
56+ </ div >
57+ < button
58+ onClick = { ( ) => setShowModal ( true ) }
59+ className = 'hover:scale-110 text-lg duration-200 mb-10 transition-all ease-out bg-ACMDARK w-60 h-10 pt-1 pb-1 rounded-lg text-white' >
60+ Checkout
61+ </ button >
62+ </ div >
63+ </ > }
64+ </ > ) }
6265 < ModalCheckOut products = { cartProducts } subTotal = { subTotal } showModal = { showModal } setShowModal = { setShowModal } />
6366 </ div >
6467 </ div >
0 commit comments