From d6c42afaec5379137a8666a13c9d169b08fa3c13 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 9 Sep 2025 04:51:29 +0200 Subject: [PATCH] fix: integrate js-cookie for install prompt dismissal handling --- .../components/install-prompt.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/thoughts-frontend/components/install-prompt.tsx b/thoughts-frontend/components/install-prompt.tsx index 399b5da..e63141b 100644 --- a/thoughts-frontend/components/install-prompt.tsx +++ b/thoughts-frontend/components/install-prompt.tsx @@ -11,6 +11,7 @@ import { CardContent, CardAction, } from "@/components/ui/card"; +import Cookies from "js-cookie"; interface CustomWindow extends Window { MSStream?: unknown; @@ -26,15 +27,20 @@ export default function InstallPrompt() { const [isStandalone, setIsStandalone] = useState(false); const [deferredPrompt, setDeferredPrompt] = useState(null); + const [isDismissed, setIsDismissed] = useState(false); useEffect(() => { - // Cast window to our custom type instead of 'any' const customWindow = window as CustomWindow; setIsIOS( /iPad|iPhone|iPod/.test(navigator.userAgent) && !customWindow.MSStream ); setIsStandalone(window.matchMedia("(display-mode: standalone)").matches); + const dismissed = Cookies.get("install_prompt_dismissed"); + if (dismissed) { + setIsDismissed(true); + } + const handleBeforeInstallPrompt = (e: Event) => { e.preventDefault(); setDeferredPrompt(e as BeforeInstallPromptEvent); @@ -58,11 +64,17 @@ export default function InstallPrompt() { console.log("User accepted the install prompt"); } else { console.log("User dismissed the install prompt"); + Cookies.set("install_prompt_dismissed", "true", { expires: 7 }); } setDeferredPrompt(null); }; - if (isStandalone || (!isIOS && !deferredPrompt)) { + const handleCloseClick = () => { + setIsStandalone(true); + Cookies.set("install_prompt_dismissed", "true", { expires: 7 }); + }; + + if (isStandalone || (!isIOS && !deferredPrompt) || isDismissed) { return null; } @@ -79,7 +91,7 @@ export default function InstallPrompt() { size="sm" variant="ghost" className="absolute top-2 right-2" - onClick={() => setIsStandalone(true)} + onClick={handleCloseClick} > ×