Files
juwan-frontend/app/(main)/post/[id]/page.tsx
T

106 lines
4.2 KiB
TypeScript

import { PostCommentCount } from "@/components/post-comment-count"
import { PostComments } from "@/components/post-comments"
import { PostLikeButton } from "@/components/post-like-button"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
import { Separator } from "@/components/ui/separator"
import { getOrderById, getPlayerById, getPostById } from "@/lib/api"
import { roleLabels } from "@/lib/constants"
import { ArrowLeft, Pin, Star } from "lucide-react"
import Image from "next/image"
import Link from "next/link"
import { notFound } from "next/navigation"
export default async function PostDetailPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params
const post = getPostById(id)
if (!post) notFound()
const linkedOrder = post.linkedOrderId ? getOrderById(post.linkedOrderId) : null
const linkedPlayer = linkedOrder ? getPlayerById(linkedOrder.playerId) : null
return (
<div className="container mx-auto max-w-2xl px-4 py-8 space-y-6">
<Link
href="/community"
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground mb-4"
>
<ArrowLeft className="h-4 w-4" />
</Link>
<Card className="hover:shadow-[var(--shadow-card)]">
<CardHeader className="pb-3">
<div className="flex items-center gap-3">
<Avatar className="h-10 w-10">
<AvatarImage src={post.author.avatar} />
<AvatarFallback>{post.author.nickname[0]}</AvatarFallback>
</Avatar>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-medium">{post.author.nickname}</span>
<Badge variant="outline" className="text-[10px] px-1.5 py-0">
{roleLabels[post.authorRole]}
</Badge>
{post.pinned && <Pin className="h-3 w-3 text-muted-foreground" />}
</div>
<span className="text-xs text-muted-foreground">
{new Date(post.createdAt).toLocaleString("zh-CN")}
</span>
</div>
</div>
</CardHeader>
<CardContent className="space-y-4">
<h1 className="text-xl font-bold tracking-tighter leading-tight">{post.title}</h1>
<p className="text-sm leading-relaxed whitespace-pre-wrap">{post.content}</p>
{post.images.length > 0 && (
<div className="flex gap-2 flex-wrap">
{post.images.map((img) => (
<div key={img} className="relative h-40 w-40 rounded-lg overflow-hidden bg-muted">
<Image src={img} alt="帖子图片" fill className="object-cover" />
</div>
))}
</div>
)}
{linkedOrder && (
<Link href={`/order/${linkedOrder.id}`}>
<div className="rounded-lg border bg-muted/30 p-3 text-sm hover:bg-muted/50 transition-colors">
<div className="flex items-center gap-2 mb-1">
<Star className="h-3.5 w-3.5 text-yellow-500" />
<span className="font-medium"></span>
</div>
<p className="text-muted-foreground text-xs">
{linkedOrder.service.gameName} · {linkedOrder.service.title} · {" "}
{linkedPlayer?.rating ?? "--"}
</p>
</div>
</Link>
)}
{post.tags.length > 0 && (
<div className="flex flex-wrap gap-1">
{post.tags.map((tag) => (
<Badge key={tag} variant="secondary" className="text-xs">
{tag}
</Badge>
))}
</div>
)}
<div className="flex items-center gap-4 text-sm text-muted-foreground pt-2">
<PostLikeButton postId={post.id} />
<PostCommentCount postId={post.id} />
</div>
</CardContent>
</Card>
<Separator className="my-6" />
<PostComments postId={id} />
</div>
)
}