'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); useEffect(() => { // 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); } }, [permission, isSubscribed, dismissed]); const handleEnable = async () => { const success = await subscribe(); if (success) { setShowPrompt(false); } }; const handleDismiss = () => { setShowPrompt(false); setDismissed(true); }; const handleDismissForever = () => { localStorage.setItem('notification-prompt-dismissed', 'true'); setShowPrompt(false); setDismissed(true); }; if (!showPrompt) { return null; } return (

Stay Updated

Get notified when items are added, completed, or when you're invited to lists

); }