新增: - 书库导入导出(library_import/library_export)及测试 - 图片变体生成(image_variants)与响应式图片(responsiveImage) - 书籍搜索(bookSearch)+ BookSearch/LibrarySearchGrid 组件 - 小组件运行时(widgetRuntime)与静态检查(widgetLint) - 上传缓存中间件(upload_cache)与字体 CSS 提取脚本 其它: - 后端 handlers/services 全量调整 - 前端页面、组件、库函数与配置更新
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { redirect } from "next/navigation";
|
||
import Link from "next/link";
|
||
import { cookies } from "next/headers";
|
||
import { authCookieHeader } from "@/lib/cookies";
|
||
import { getMeCached } from "@/lib/serverData";
|
||
import { fetchNotifications } from "@/lib/api";
|
||
import Pagination from "@/components/Pagination";
|
||
import NotificationsClient from "./NotificationsClient";
|
||
|
||
interface NotificationsPageProps {
|
||
searchParams: Promise<{ page?: string }>;
|
||
}
|
||
|
||
// SSR 直出通知列表:F5 直接看到内容,不再先渲染"正在加载…"
|
||
export default async function NotificationsPage({ searchParams }: NotificationsPageProps) {
|
||
const sp = await searchParams;
|
||
const page = Math.max(1, parseInt(sp.page || "1", 10) || 1);
|
||
const cookie = authCookieHeader(await cookies());
|
||
const me = await getMeCached(cookie || undefined);
|
||
if (!me.user) {
|
||
redirect(`/login?redirect=${encodeURIComponent(`/notifications`)}`);
|
||
}
|
||
|
||
let data = null;
|
||
let loadError = false;
|
||
try {
|
||
data = await fetchNotifications(page, cookie);
|
||
} catch {
|
||
loadError = true;
|
||
}
|
||
|
||
return (
|
||
<div className="w-full">
|
||
<h1 className="text-[22px] sm:text-[26px] font-extrabold tracking-tight mb-4 sm:mb-5" style={{ color: "var(--ink)" }}>
|
||
通知中心
|
||
</h1>
|
||
|
||
{loadError || !data ? (
|
||
<div className="panel text-center py-16 px-6" role="alert">
|
||
<p className="text-sm font-semibold" style={{ color: "var(--ink-2)" }}>通知加载失败</p>
|
||
<p className="meta mt-1.5 mb-4">网络异常,请稍后重试</p>
|
||
<Link href="/notifications" className="btn btn-line btn-sm">重新加载</Link>
|
||
</div>
|
||
) : (
|
||
<div className="grid gap-4 items-start lg:grid-cols-[248px_minmax(0,1fr)]">
|
||
{/* 左栏 sticky 概览 + 全部已读(客户端组件,行内未读数点击后同步刷新);右列列表 + 分页 */}
|
||
<NotificationsClient initialData={data} initialUnread={me.unread_count}>
|
||
<Pagination
|
||
total={data.total}
|
||
page={data.page}
|
||
size={data.size}
|
||
basePath="/notifications"
|
||
/>
|
||
</NotificationsClient>
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|