import { Bell, Check, ChevronRight } from "lucide-react"; import { Button } from "@/components/ui/button"; import { api } from "@/client"; import { useQuery } from "@tanstack/react-query"; import { useAuth } from "@/context/auth-context"; interface NotificationItem { id: string; title: string; body: string; read_at?: string | null; created_at: string; } export default function MeNotificationsPage() { const { me } = useAuth(); const unreadCount = me?.has_unread_notifications ?? 0; const { data: notifications, isLoading } = useQuery({ queryKey: ["user", "notifications"], queryFn: async () => { const res = await api.get("/api/v1/ws/notifications"); return res.data; }, retry: false, }); return (

Notifications

{unreadCount > 0 ? `${unreadCount} unread` : "All caught up"}

{unreadCount > 0 && ( )}
{isLoading ? ( Array.from({ length: 3 }).map((_, i) => (
)) ) : (notifications ?? []).length > 0 ? ( notifications!.map((notif: NotificationItem) => (

{notif.title}

{notif.body}

{formatTime(notif.created_at)}
)) ) : (

No notifications yet

)}
); } function formatTime(dateStr: string): string { const date = new Date(dateStr); const now = new Date(); const diff = now.getTime() - date.getTime(); const minutes = Math.floor(diff / 60000); const hours = Math.floor(diff / 3600000); const days = Math.floor(diff / 86400000); if (minutes < 1) return "just now"; if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; if (days < 7) return `${days}d ago`; return date.toLocaleDateString(); }