import Link from "next/link"; import { FileText, MessageCircle, AlertCircle, Bookmark, UserPlus, } from "lucide-react"; import Pagination from "@/components/Pagination"; import PostRow from "@/components/PostRow"; import { IconComment, IconEye, IconHeart } from "@/components/Icons"; import Avatar from "@/components/Avatar"; import LevelBadge from "@/components/LevelBadge"; import FollowButton from "@/components/FollowButton"; import { formatRelative } from "@/lib/format"; import type { UserProfile, UserCommentsResponse, UserFavoritesResponse, UserFollowingResponse, PostListItem, } from "@/lib/api"; /** 本页卡片统一阴影;用 color-mix 让暗色主题自动加深,避免写死浅色阴影 */ const CARD_SHADOW = "0 1px 3px color-mix(in srgb, #000 18%, transparent)"; const ITEM_BASE = "group block rounded-xl px-6 py-5 border transition-[background-color,box-shadow,border-color] duration-150"; const SORTS: { key: string; label: string }[] = [ { key: "new", label: "最新" }, { key: "hot", label: "热门" }, { key: "essence", label: "精华" }, ]; /** 帖子卡(发帖列表与收藏列表共用) */ function PostCardItem({ post, allowComments }: { post: PostListItem; allowComments?: boolean }) { const pinned = post.pinned > 0; return (
{pinned && ( 置顶 )}

{post.title}

{post.recommended && 推荐}
{post.board.name} {formatRelative(post.created_at)} {allowComments ? ( {post.comment_count} 评论 ) : null} {post.view_count} 浏览 {post.like_count} 点赞
); } /** 列表区块统一空态 */ function EmptyState({ icon, text }: { icon: React.ReactNode; text: string }) { return (
{icon}

{text}

); } /** 列表加载失败统一态 */ function ErrorState({ retryHref }: { retryHref: string }) { return (

加载失败

网络异常,请稍后重试

重新加载
); } /** * 用户主页内容区(纯服务端渲染): * tab 与分页全部走 URL(?tab=xxx&page=N&sort=xxx),刷新/后退/分享链接均保持一致。 * Tab 切换栏已移至 page.tsx 统一渲染(含 settings / security),此组件仅负责列表类 tab。 */ export default function UserProfileContent({ userId, profile, tab, commentData, commentError, favoriteData, favoriteError, followingData, followingError, page, sort = "new", isOwner, allowComments = true, }: { userId: string; profile: UserProfile; tab: "posts" | "comments" | "favorites" | "following"; commentData: UserCommentsResponse | null; commentError: boolean; favoriteData: UserFavoritesResponse | null; favoriteError: boolean; followingData: UserFollowingResponse | null; followingError: boolean; page: number; sort?: string; isOwner: boolean; allowComments?: boolean; }) { const displayName = profile.user.nickname || profile.user.username; const paginationQuery: Record = tab === "comments" ? { tab: "comments" } : tab === "favorites" ? { tab: "favorites" } : tab === "following" ? { tab: "following" } : sort !== "new" ? { sort } : {}; return (
{tab === "posts" ? (
{/* 标题 + 排序 chips(最新/热门/精华),与参考图一致 */}

{isOwner ? "我的帖子" : `${displayName} 的帖子`}

{SORTS.map((s) => ( {s.label} ))}
{Array.isArray(profile.posts) && profile.posts.length > 0 ? ( /* 与首页信息流一致的行式列表 */
{profile.posts.map((post, i) => ( ))}
) : ( } text="暂无发帖" /> )}
) : tab === "favorites" ? ( favoriteError ? ( ) : favoriteData && favoriteData.posts.length > 0 ? (

{isOwner ? "我的收藏" : `${displayName} 的收藏`}

{favoriteData.posts.map((post) => ( ))}
) : ( } text="暂无收藏" /> ) ) : tab === "following" ? ( followingError ? ( ) : followingData && followingData.users.length > 0 ? (

{isOwner ? "我的关注" : `${displayName} 的关注`}

{followingData.users.map((fu) => (
{fu.nickname || fu.username}

@{fu.username} {fu.signature ? ` · ${fu.signature}` : ""}

{isOwner && }
))}
) : ( } text="暂无关注" /> ) ) : commentError ? ( ) : commentData && (commentData.comments?.length ?? 0) > 0 ? (
{(commentData.comments ?? []).map((c) => (
评论于《{c.post_title}》

{c.content}

{formatRelative(c.created_at)}
))}
) : ( } text="暂无评论" /> )}
); }