import React, { useEffect, useState } from 'react'; import { Check, Bell } from 'lucide-react'; import { supabase } from '../lib/supabase'; export default function NotificationCenter({ userId }) { const [notifications, setNotifications] = useState([]); const [loading, setLoading] = useState(true); const [updating, setUpdating] = useState({}); useEffect(() => { if (!userId) return; const fetchNotifications = async () => { setLoading(true); const { data, error } = await supabase .from('notifications') .select('*') .eq('user_id', userId) .eq('seen', false) .order('created_at', { ascending: false }); if (!error) setNotifications(data || []); setLoading(false); }; fetchNotifications(); }, [userId]); const markAsSeen = async (id) => { setUpdating(u => ({ ...u, [id]: true })); await supabase .from('notifications') .update({ seen: true }) .eq('id', id); setNotifications(n => n.filter(notif => notif.id !== id)); setUpdating(u => ({ ...u, [id]: false })); }; if (loading) { return (
{[1, 2].map((i) => (
))}
); } if (!notifications.length) return null; return (
{notifications.map((notif) => (

{notif.message}

))}
); }