From de1e3c668cf66329ad2f27ec42a4295c7fdbc96f Mon Sep 17 00:00:00 2001 From: hta218 Date: Fri, 13 Dec 2024 11:46:54 +0700 Subject: [PATCH] Fix open cart drawer on header --- app/components/header/cart-count.tsx | 16 ++------ app/components/header/desktop-header.tsx | 8 +--- app/components/header/index.tsx | 47 +++--------------------- app/components/header/mobile-header.tsx | 14 ++----- 4 files changed, 13 insertions(+), 72 deletions(-) diff --git a/app/components/header/cart-count.tsx b/app/components/header/cart-count.tsx index 34a715d6..dba7e42b 100644 --- a/app/components/header/cart-count.tsx +++ b/app/components/header/cart-count.tsx @@ -7,11 +7,9 @@ import { useIsHydrated } from "~/hooks/use-is-hydrated"; import type { RootLoader } from "~/root"; export function CartCount({ - isHome, openCart, isTransparent, }: { - isHome: boolean; openCart: () => void; isTransparent: boolean; }) { @@ -19,18 +17,12 @@ export function CartCount({ return ( + } > {(cart) => ( void; cart?: any; isTransparent: boolean; @@ -63,11 +53,11 @@ function Badge({ {count > 0 && (
- {}} - isTransparent={isTransparent} - /> +
diff --git a/app/components/header/index.tsx b/app/components/header/index.tsx index 33f5e605..e70e7004 100644 --- a/app/components/header/index.tsx +++ b/app/components/header/index.tsx @@ -1,21 +1,13 @@ -import { Await, useRouteLoaderData } from "@remix-run/react"; -import { CartForm, type CartReturn } from "@shopify/hydrogen"; -import { Suspense, useEffect } from "react"; +import { CartForm } from "@shopify/hydrogen"; +import { useEffect } from "react"; import { useCartFetchers } from "~/hooks/use-cart-fetchers"; -import { Cart } from "~/modules/cart"; -import type { RootLoader } from "~/root"; -import { CartLoading } from "../../modules/cart-loading"; -import { Drawer, useDrawer } from "../../modules/drawer"; +import { useDrawer } from "../../modules/drawer"; import { DesktopHeader } from "./desktop-header"; import { MobileHeader } from "./mobile-header"; import { ScrollingAnnouncement } from "./scrolling-announcement"; export function Header() { - let { - isOpen: isCartOpen, - openDrawer: openCart, - closeDrawer: closeCart, - } = useDrawer(); + let { isOpen: isCartOpen, openDrawer: openCart } = useDrawer(); let addToCartFetchers = useCartFetchers(CartForm.ACTIONS.LinesAdd); // toggle cart drawer when adding to cart @@ -26,38 +18,9 @@ export function Header() { return ( <> - {/* */} - + ); } - -function CartDrawer({ - isOpen, - onClose, -}: { - isOpen: boolean; - onClose: () => void; -}) { - const rootData = useRouteLoaderData("root"); - - return ( - -
- }> - - {(cart) => ( - - )} - - -
-
- ); -} diff --git a/app/components/header/mobile-header.tsx b/app/components/header/mobile-header.tsx index abea793b..293f3ae7 100644 --- a/app/components/header/mobile-header.tsx +++ b/app/components/header/mobile-header.tsx @@ -13,14 +13,10 @@ import { Logo } from "~/components/logo"; import { cn } from "~/lib/cn"; import { useIsHomePath } from "~/lib/utils"; import type { RootLoader } from "~/root"; -import { CartCount } from "./cart-count"; +import { CartDrawer } from "./cart-drawer"; import { MobileMenu } from "./menu/mobile-menu"; -export function MobileHeader({ - openCart, -}: { - openCart: () => void; -}) { +export function MobileHeader() { let isHome = useIsHomePath(); let { enableTransparentHeader } = useThemeSettings(); let { y } = useWindowScroll(); @@ -65,11 +61,7 @@ export function MobileHeader({
- +
);