import Link from "next/link"; import { Metadata } from "next"; import { ChevronRight, FileText, MessageCircle } from "lucide-react"; import { fetchUserProfile, type UserProfile } from "@/lib/api"; import UserProfileClient from "./UserProfileClient"; import Avatar from "@/components/Avatar"; interface UserPageProps { params: Promise<{ id: string }>; searchParams: Promise<{ page?: string; tab?: string }>; } export async function generateMetadata({ params }: UserPageProps): Promise { const { id } = await params; try { const data = await fetchUserProfile(id, 1); return { title: data.user.nickname || data.user.username, description: `查看 ${data.user.nickname} 的资料、发帖与评论`, }; } catch { return { title: "用户不存在" }; } } export default async function UserPage({ params, searchParams }: UserPageProps) { const { id } = await params; const { page: pageStr } = await searchParams; const page = Math.max(1, parseInt(pageStr || "1", 10) || 1); let data: UserProfile; try { data = await fetchUserProfile(id, page); } catch { return (

用户不存在

该用户可能已注销或链接有误

返回首页
); } const u = data.user; const stats = [ { label: "发帖", value: data.stats.post_count, icon: }, { label: "评论", value: data.stats.comment_count, icon: }, ]; return (
{/* 用户信息卡片 */}

{u.nickname || u.username}

{u.role === "admin" && ( 管理员 )}

@{u.username} · {new Date(u.created_at).toLocaleDateString("zh-CN")} 加入

{stats.map((s) => ( {s.icon} {s.value} {s.label} ))}
{/* 发帖 / 评论 切换 */}
); }