From 1ba72fe7685d506416d9ffdf63d46ea49a999bc4 Mon Sep 17 00:00:00 2001 From: Cooper Ransom Date: Tue, 26 Mar 2024 13:31:49 -0400 Subject: [PATCH] implement isMobile into extension banner --- src/setup/Layout.tsx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/setup/Layout.tsx b/src/setup/Layout.tsx index 5b2dbaac..66372346 100644 --- a/src/setup/Layout.tsx +++ b/src/setup/Layout.tsx @@ -2,6 +2,7 @@ import { ReactNode, useEffect, useState } from "react"; import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; import { extensionInfo } from "@/backend/extension/messaging"; +import { useIsMobile } from "@/hooks/useIsMobile"; import { useBannerSize, useBannerStore } from "@/stores/banner"; import { ExtensionBanner } from "@/stores/banner/BannerLocation"; @@ -28,7 +29,7 @@ export function Layout(props: { children: ReactNode }) { const location = useBannerStore((s) => s.location); const [extensionState, setExtensionState] = useState("unknown"); - const [isMobile, setIsMobile] = useState(false); + const { isMobile } = useIsMobile(); useEffect(() => { let isMounted = true; @@ -39,19 +40,8 @@ export function Layout(props: { children: ReactNode }) { } }); - // Instead use isMobile like this `const { isMobile } = useIsMobile();` - const mediaQuery = window.matchMedia("(max-width: 768px)"); // Adjust the max-width as per your needs - setIsMobile(mediaQuery.matches); - - const handleResize = () => { - setIsMobile(mediaQuery.matches); - }; - - mediaQuery.addListener(handleResize); - return () => { isMounted = false; - mediaQuery.removeListener(handleResize); }; }, []);