"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { api } from "@community/lib/api"; import { useAuth } from "@community/lib/auth"; import { useI18n } from "@community/lib/i18n"; import type { NotificationItem } from "@community/lib/types"; import RingNext from "@community/components/RingNext"; import { useRingSteps } from "@community/lib/rings"; export default function NotificationsClient() { const { token } = useAuth(); const { t } = useI18n(); const rings = useRingSteps(); const [items, setItems] = useState([]); const [loading, setLoading] = useState(Boolean(token)); useEffect(() => { if (!token) { setItems([]); setLoading(false); return; } setLoading(true); api .getNotifications(token) .then(setItems) .catch(() => setItems([])) .finally(() => setLoading(false)); }, [token]); const markAll = async () => { if (!token) return; await api.markNotificationsRead(token).catch(() => null); setItems((list) => list.map((n) => ({ ...n, read: true }))); }; const openOne = async (n: NotificationItem) => { if (!token || n.read) return; await api.notificationAction(token, n.id, "read").catch(() => null); setItems((list) => list.map((x) => (x.id === n.id ? { ...x, read: true } : x))); }; if (!token) { return (

{t.notifications.title}

{t.notifications.loginDesc}

{t.nav.login} {t.nav.meetups} {t.nav.community}
); } return (

{t.notifications.title}

{t.notifSettings.title}
{loading &&

{t.common.loading}

} {!loading && items.map((n) => (
{n.title}

{n.body}

{n.created_at}
{n.link ? ( { void openOne(n); }} > {t.common.open} ) : ( !n.read && ( ) )}
))} {!loading && items.length === 0 && (

{t.notifications.empty}

{t.notifications.emptyHint}

{t.nav.meetups} {t.nav.dating} {t.nav.community}
)}
); }