import { Loader2, Tv } 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 EPISODE_KINDS: NotificationKind[] = ['new_episode', 'new_season'] 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'), new_episode: () => '', new_season: () => '', } /** Liste des notifications (abonnements, réactions, nouveaux épisodes). Marque comme lues à l'ouverture. */ export default function Notifications({ onClose, onOpenProfile, onOpenItem }: { onClose: () => void; onOpenProfile: (username: string) => void; onOpenItem: (itemId: 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) } } 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, onOpenItem }: { n: AppNotification; onOpenProfile: (username: string) => void; onOpenItem: (itemId: string) => void }) { const unread = n.read_at === null const isEpisode = EPISODE_KINDS.includes(n.kind) const base = cx('flex items-center gap-3 border-b border-line px-4 py-3 text-start', unread && 'bg-surface-2') // ── Nouvel épisode / nouvelle saison ── if (isEpisode) { const title = n.title ?? '—' const inner = ( <> {unread &&