import React from 'react'
import { useNavigate } from 'react-router-dom'
import { Bell, Heart, MessageCircle, Users, Settings, Check, ExternalLink } from 'lucide-react'
import { useNotificationStore } from '../store/notificationStore'
import { useAuthStore } from '../store/authStore'
import { Button } from '../components/ui/Button'
import { NotificationType } from '../types'
const typeIcon = (type: NotificationType) => {
switch (type) {
case 'like': return
case 'comment': return
case 'collaboration': return
case 'system': return
default: return
}
}
function formatDate(str: string) {
return new Date(str).toLocaleDateString('en-US', {
month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit',
})
}
export const NotificationsPage: React.FC = () => {
const navigate = useNavigate()
const { currentUser } = useAuthStore()
const { notifications, markAllRead, markRead } = useNotificationStore()
if (!currentUser) {
return (
Sign in to view notifications
)
}
const userNotifications = notifications
const unread = userNotifications.filter(n => !n.is_read)
return (
Notifications
{unread.length > 0 && (
{unread.length} unread
)}
{unread.length > 0 && (
)}
{userNotifications.length === 0 ? (
No notifications yet
You'll see activity here when readers interact with your content.
) : (
{userNotifications.map(n => (
{
markRead(n.notification_id)
if (n.link) navigate(n.link)
}}
>
{typeIcon(n.type)}
{n.title}
{!n.is_read && (
)}
{n.link && (
)}
{n.message}
{formatDate(n.created_at)}
))}
)}
)
}