'use client'; import { useEffect, useState } from 'react'; import { usePushNotifications } from '@/hooks/usePushNotifications'; import { Bell, X } from 'lucide-react'; export default function NotificationPrompt() { const { permission, isSubscribed, subscribe } = usePushNotifications(); const [showPrompt, setShowPrompt] = useState(false); const [dismissed, setDismissed] = useState(false); const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); useEffect(() => { if (!mounted) return; // Check if we should show the prompt const shouldShow = 'Notification' in window && 'serviceWorker' in navigator && permission === 'default' && // Not yet asked !isSubscribed && // Not subscribed !dismissed && // Not dismissed this session !localStorage.getItem('notification-prompt-dismissed'); // Not permanently dismissed if (shouldShow) { // Show prompt after a short delay (better UX) const timer = setTimeout(() => { setShowPrompt(true); }, 3000); // 3 seconds after app loads return () => clearTimeout(timer); } }, [mounted, permission, isSubscribed, dismissed]); const handleEnable = async () => { const success = await subscribe(); if (success) { setShowPrompt(false); } }; const handleDismiss = () => { setShowPrompt(false); setDismissed(true); }; const handleDismissForever = () => { if (typeof localStorage !== 'undefined') { localStorage.setItem('notification-prompt-dismissed', 'true'); } setShowPrompt(false); setDismissed(true); }; if (!mounted || !showPrompt) { return null; } return (
Get notified when items are added, completed, or when you're invited to lists