Skip to content

Commit

Permalink
implement isMobile into extension banner
Browse files Browse the repository at this point in the history
  • Loading branch information
itzCozi committed Mar 26, 2024
1 parent cfd43c7 commit 1ba72fe
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/setup/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -28,7 +29,7 @@ export function Layout(props: { children: ReactNode }) {
const location = useBannerStore((s) => s.location);
const [extensionState, setExtensionState] =
useState<ExtensionStatus>("unknown");
const [isMobile, setIsMobile] = useState(false);
const { isMobile } = useIsMobile();

useEffect(() => {
let isMounted = true;
Expand All @@ -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);
};
}, []);

Expand Down

0 comments on commit 1ba72fe

Please sign in to comment.