import Link from "next/link"; import { ArrowLeft } from "lucide-react"; import type { PostListItem } from "@/lib/api"; import { formatRelative } from "@/lib/format"; import { getPublicSettingsCached } from "@/lib/serverData"; import { normalizePostType, postTypeLabel, contentAccessLabel, typeStatusLabel, typeStatusClass } from "@/lib/postMeta"; import LikeButton from "./LikeButton"; import Avatar from "./Avatar"; import { IconComment, IconEye } from "./Icons"; /** * 帖子列表行(参考社区信息流样式): * 大头像 + 标题(徽章内联)+ 第二行「板块 · 作者 · 发布时间 ← 最后回复」+ * 右侧评论数等统计垂直居中。用于首页/板块页/搜索结果。 * * 点击:标题 stretch-link 铺满整行进帖;仅头像/作者/回复者/点赞等加 above-link 抬层。 * 板块胶囊仅展示,不可点,避免误进板块筛选。 */ export default async function PostRow({ post, showBoard = false, index = 0, compact = false, showViews = true, showLike = true, }: { post: PostListItem; index?: number; /** 是否展示板块胶囊(不可点击,仅标识) */ showBoard?: boolean; compact?: boolean; showViews?: boolean; showLike?: boolean; }) { const allowComments = (await getPublicSettingsCached()).allow_comments !== false; const lastReply = post.last_reply; const replied = allowComments && lastReply && new Date(lastReply.created_at).getTime() > new Date(post.created_at).getTime() + 60_000; const pt = normalizePostType(post.post_type); const statusBadge = pt !== "discussion" ? typeStatusLabel(pt, post.type_status) : ""; const statusClass = statusBadge ? typeStatusClass(pt, post.type_status) : ""; const authorName = post.user.nickname || post.user.username; return (
{/* 仅置顶/推荐在标题左侧 */} {post.pinned > 0 && 置顶} {post.recommended && 推荐}

{post.title}

{/* 其余徽章紧跟标题右侧 */} {post.status === "pending" && 待审} {pt !== "discussion" && pt !== "question" && ( {postTypeLabel(post.post_type)} )} {statusBadge && statusClass && ( {statusBadge} )} {post.content_access && post.content_access !== "public" && ( {contentAccessLabel(post.content_access)} )}
{showBoard && ( {post.board.name} )} {authorName} · {formatRelative(post.created_at)} {replied && ( {lastReply!.user.nickname || lastReply!.user.username} {formatRelative(lastReply!.created_at)} )} {!replied && allowComments && post.comment_count === 0 && ( · 暂无回复 )}
{allowComments ? ( {post.comment_count} ) : null} {showViews && ( {post.view_count} )} {showLike && (
)}
); }