'use client'; // 消息页:通知列表(回复/删除/举报处理/系统) import { useEffect, useState } from 'react'; import { API } from '@/lib/api'; import { useApp } from './AppProvider'; import { Icon } from './Icons'; const TYPE_MAP = { reply: 'message', post_deleted: 'trash', report_handled: 'shield', system: 'megaphone' }; export default function MessagesPage() { const { currentUser } = useApp(); const [notifications, setNotifications] = useState(null); const [error, setError] = useState(null); useEffect(() => { if (!currentUser) return; API.getNotifications() .then((data) => { setNotifications(data || []); setError(null); API.markAllNotificationsRead().catch(() => {}); }) .catch((e) => { setError(e.message); setNotifications([]); }); }, [currentUser]); if (!currentUser) { return
请先登录
; } return (

消息

{error ? (
加载失败:{error}
) : notifications === null ? (
加载中...
) : notifications.length === 0 ? (

暂无消息

当有人回复你的帖子或处理你的举报时,会在这里通知你

) : ( notifications.map((n) => { const icon = TYPE_MAP[n.type] || 'pin'; const time = n.created_at ? new Date(n.created_at).toLocaleString('zh-CN') : ''; return (
{n.title}
{n.content}
{n.link && 查看详情 →}
{time}
); }) )}
); }