import { Loader2 } from 'lucide-react' import { useEffect, useState } from 'react' import { t } from '../../i18n' import { listNotifications, markNotificationsRead, type AppNotification, type NotificationKind } from '../../lib/cloud/notifications' import { cx, formatDate } from '../../lib/utils' import { EmptyState } from '../ui' import Avatar from './Avatar' import Sheet from './Sheet' const PAGE = 30 const FOLLOW_KINDS: NotificationKind[] = ['follow_request', 'follow_accepted', 'new_follower'] const VERB: Record string> = { follow_request: () => t('notif.follow_request'), follow_accepted: () => t('notif.follow_accepted'), new_follower: () => t('notif.new_follower'), reaction: () => t('notif.reaction'), } /** Liste des notifications (abonnements, demandes acceptées, réactions). Marque comme lues à l'ouverture. */ export default function Notifications({ onClose, onOpenProfile }: { onClose: () => void; onOpenProfile: (username: string) => void }) { const [items, setItems] = useState(undefined) const [done, setDone] = useState(false) const [loadingMore, setLoadingMore] = useState(false) useEffect(() => { let alive = true void (async () => { try { const page = await listNotifications(0) if (!alive) return setItems(page) setDone(page.length < PAGE) } catch { if (alive) { setItems([]) setDone(true) } } // Marque comme lu (feu et oubli) pour vider le badge markNotificationsRead().catch(() => {}) })() return () => { alive = false } }, []) const loadMore = async () => { if (!items || loadingMore) return setLoadingMore(true) try { const page = await listNotifications(items.length) setItems((prev) => [...(prev ?? []), ...page]) setDone(page.length < PAGE) } catch { setDone(true) } finally { setLoadingMore(false) } } return ( {items === undefined ? (

) : items.length === 0 ? (
) : (
    {items.map((n) => ( ))} {!done && (
  • )}
)}
) } function Row({ n, onOpenProfile }: { n: AppNotification; onOpenProfile: (username: string) => void }) { const actor = n.actor const actorName = actor?.display_name ?? t('notif.someone') const unread = n.read_at === null const username = actor?.username const target = username != null && FOLLOW_KINDS.includes(n.kind) ? username : null const inner = ( <> {unread &&