"use client"; /** * notifications-widget(universal / main) * * 通过 useNotifications 查询 apollo-router → msg 子图的 notifications 数据。 * 与 topbar 的 notification-bell 区别:本插件位于 main 区,展示完整列表 * (含标题、正文、时间、类型徽章),bell 仅在顶栏做徽标提示。 * * 关联:portal-shell spec §5.6 统一 Hook、M8 验收 */ import { useNotifications } from "@/lib/api/universal"; import { PluginSkeleton } from "@/shell/PluginLoader"; import type { PluginProps } from "@/lib/types"; const TYPE_LABEL: Record = { info: "通知", warning: "提醒", urgent: "紧急", }; function TypeBadge({ type }: { type: string }): React.ReactElement { const label = TYPE_LABEL[type] ?? type; if (type === "urgent") { return ( {label} ); } if (type === "warning") { return ( {label} ); } return ( {label} ); } export default function NotificationsWidget( props: PluginProps, ): React.ReactElement { const rawLimit = props.props.limit; const limit = typeof rawLimit === "number" ? rawLimit : 20; const { data, loading } = useNotifications({ limit, offset: 0 }); if (loading && !data) { return ; } const items = data?.items ?? []; const total = data?.total ?? 0; return (

通知

共 {total} 条
{items.length === 0 ? (

暂无通知

) : (
    {items.map((item) => (
  • {item.title}

    {item.body}

    {item.createdAt}

  • ))}
)}
); }