From 18102bfb72675e5a3be960ef12336d3fd4d01190 Mon Sep 17 00:00:00 2001 From: Martin Bavio Date: Fri, 30 Oct 2020 16:57:10 -0300 Subject: [PATCH] Add cart loading skeleton and complete the task --- components/cart/CartEmpty/index.tsx | 23 ++++++++ components/cart/CartSkeleton/index.tsx | 76 ++++++++++++++++++++++++++ lib/hooks/use-cart.ts | 6 +- pages/cart.tsx | 30 ++++------ tailwind.config.js | 14 +++++ 5 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 components/cart/CartEmpty/index.tsx create mode 100644 components/cart/CartSkeleton/index.tsx diff --git a/components/cart/CartEmpty/index.tsx b/components/cart/CartEmpty/index.tsx new file mode 100644 index 000000000..dd5e7e971 --- /dev/null +++ b/components/cart/CartEmpty/index.tsx @@ -0,0 +1,23 @@ +import { Bag } from '@components/icons' +import { Button } from '@components/ui' + +const CartEmpty: React.FC = () => { + return ( +
+ + + +

+ Your cart is empty +

+

+ Biscuit oat cake wafer icing ice cream tiramisu pudding cupcake. +

+ +
+ ) +} + +export default CartEmpty diff --git a/components/cart/CartSkeleton/index.tsx b/components/cart/CartSkeleton/index.tsx new file mode 100644 index 000000000..a93a8a27c --- /dev/null +++ b/components/cart/CartSkeleton/index.tsx @@ -0,0 +1,76 @@ +const CartSkeleton: React.FC = () => { + return ( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+
+
+
+
+
+
+
+
+
+
+ ) +} + +export default CartSkeleton diff --git a/lib/hooks/use-cart.ts b/lib/hooks/use-cart.ts index 0ccf60159..a0632d9bf 100644 --- a/lib/hooks/use-cart.ts +++ b/lib/hooks/use-cart.ts @@ -3,7 +3,7 @@ import useBigCommercePrice from '@bigcommerce/storefront-data-hooks/use-price' export const useCart = () => { const { data, error, isEmpty } = useBigCommerceCart() - const isLoading = data === undefined + const items = data?.line_items.physical_items ?? [] const { price: subtotal } = useBigCommercePrice( data && { @@ -18,13 +18,11 @@ export const useCart = () => { } ) - const items = data?.line_items.physical_items ?? [] - return { items: data?.line_items.physical_items ?? [], isLoading: data === undefined, isError: error, - isEmpty: isEmpty && data == null, + isEmpty: isEmpty && data === null, subtotal, total, currency: data?.currency, diff --git a/pages/cart.tsx b/pages/cart.tsx index 9da479a7d..3e853feea 100644 --- a/pages/cart.tsx +++ b/pages/cart.tsx @@ -7,6 +7,8 @@ import { Button } from '@components/ui' import { Bag, Cross, Check } from '@components/icons' import { CartItem } from '@components/cart' import { Text } from '@components/ui' +import CartSkeleton from '@components/cart/CartSkeleton' +import CartEmpty from '@components/cart/CartEmpty' export async function getStaticProps({ preview, @@ -33,23 +35,12 @@ export default function Cart() { return (
My Cart - {isError &&
Failed to load
} - {isLoading &&
Loading...
} - {isEmpty ? ( -
- - - -

- Your cart is empty -

-

- Biscuit oat cake wafer icing ice cream tiramisu pudding cupcake. -

- -
+ {true ? ( + + ) : isError ? ( +
Failed to load
+ ) : isEmpty ? ( + ) : (
@@ -72,7 +63,10 @@ export default function Cart() {
{[1, 2, 3, 4, 5, 6].map((x) => ( -
+
))}
diff --git a/tailwind.config.js b/tailwind.config.js index fcadb5892..f41011b49 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -49,6 +49,20 @@ module.exports = { magical: 'rgba(0, 0, 0, 0.02) 0px 30px 30px, rgba(0, 0, 0, 0.03) 0px 0px 8px, rgba(0, 0, 0, 0.05) 0px 1px 0px', }, + animation: { + 'cart-pulse': 'pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite', + }, + + keyframes: { + 'cart-pulse': { + '0%, 100%': { + opacity: 0.2, + }, + '50%': { + opacity: 1, + }, + }, + }, }, }, plugins: [require('@tailwindcss/ui')],