Skip to content

Commit

Permalink
Merge pull request Weaverse#204 from Weaverse/dev
Browse files Browse the repository at this point in the history
Fix cart logic
  • Loading branch information
hta218 authored Sep 6, 2024
2 parents 16497c1 + cb1659a commit abdd3b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
28 changes: 12 additions & 16 deletions app/modules/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ export function Cart({
}) {
let optimisticCart = useOptimisticCart<CartApiQueryFragment>(cart);
let linesCount = Boolean(optimisticCart?.lines?.nodes?.length || 0);
let cartHasItems = !!cart && cart.totalQuantity > 0;

return (
<>
<CartEmpty hidden={linesCount} onClose={onClose} layout={layout} />
<CartDetails cart={optimisticCart} layout={layout} />
</>
);
if (cartHasItems) {
return <CartDetails cart={optimisticCart} layout={layout} />;
}
return <CartEmpty hidden={linesCount} onClose={onClose} layout={layout} />;
}

export function CartDetails({
Expand All @@ -52,7 +51,6 @@ export function CartDetails({
layout: Layouts;
cart: OptimisticCart<CartApiQueryFragment>;
}) {
let cartHasItems = !!cart && cart.totalQuantity > 0;
return (
<div
className={clsx(
Expand All @@ -66,12 +64,10 @@ export function CartDetails({
)}
>
<CartLines lines={cart?.lines?.nodes} layout={layout} />
{cartHasItems && (
<CartSummary cost={cart.cost} layout={layout}>
<CartDiscounts discountCodes={cart.discountCodes} />
<CartCheckoutActions checkoutUrl={cart.checkoutUrl} layout={layout} />
</CartSummary>
)}
<CartSummary cost={cart.cost} layout={layout}>
<CartDiscounts discountCodes={cart.discountCodes} />
<CartCheckoutActions checkoutUrl={cart.checkoutUrl} layout={layout} />
</CartSummary>
</div>
);
}
Expand Down Expand Up @@ -486,17 +482,17 @@ export function CartEmpty({
)}
hidden={hidden}
>
<div>
<div className={clsx(layout === "page" && "text-center")}>
<p className="mb-4">
Looks like you haven&rsquo;t added anything yet, let&rsquo;s get you
started!
</p>
<Button
className={clsx(layout === "drawer" ? "w-full" : "")}
className={clsx(layout === "drawer" ? "w-full" : "min-w-48")}
link={layout === "page" ? "/products" : ""}
onClick={onClose}
>
Continue shopping
Start Shopping
</Button>
</div>
<div className="grid gap-4">
Expand Down
7 changes: 6 additions & 1 deletion app/modules/header/mobile-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ export function MobileHeader({
}) {
// useHeaderStyleFix(containerStyle, setContainerStyle, isHome);
let isHome = useIsHomePath();
let { enableTransparentHeader } = useThemeSettings();
let { enableTransparentHeader, topbarHeight } = useThemeSettings();
let { y } = useWindowScroll();
let params = useParams();
let scrolled = y >= 50;
let isTransparent = enableTransparentHeader && isHome && !scrolled;

return (
<header
style={
{
"--initial-topbar-height": `${topbarHeight}px`,
} as React.CSSProperties
}
className={cn(
"transition-colors duration-300 ease-in-out",
"h-nav z-40 top-[var(--topbar-height,var(--initial-topbar-height))] w-full leading-none",
Expand Down

0 comments on commit abdd3b3

Please sign in to comment.