feat: wire post interactions and persist favorites state
This commit is contained in:
@@ -2,12 +2,11 @@ import { ArrowLeft, Heart, MessageCircle, Pin, Star } from "lucide-react"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { notFound } from "next/navigation"
|
||||
import { PostComments } from "@/components/post-comments"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardHeader } from "@/components/ui/card"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { roleLabels } from "@/lib/constants"
|
||||
import { mockComments, mockOrders, mockPlayers, mockPosts } from "@/lib/mock"
|
||||
|
||||
@@ -112,47 +111,7 @@ export default async function PostDetailPage({ params }: { params: Promise<{ id:
|
||||
|
||||
<Separator className="my-6" />
|
||||
|
||||
<div className="space-y-4">
|
||||
<h2 className="font-semibold">评论 ({comments.length})</h2>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<Textarea placeholder="写下你的评论..." className="flex-1" rows={2} />
|
||||
<Button className="self-end">发送</Button>
|
||||
</div>
|
||||
|
||||
{comments.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground text-center py-8">还没有评论</p>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{comments.map((comment) => (
|
||||
<div key={comment.id} className="flex gap-3">
|
||||
<Avatar className="h-8 w-8">
|
||||
<AvatarImage src={comment.author.avatar} />
|
||||
<AvatarFallback>{comment.author.nickname[0]}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-0.5">
|
||||
<span className="text-sm font-medium">{comment.author.nickname}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{new Date(comment.createdAt).toLocaleString("zh-CN")}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-sm">{comment.content}</p>
|
||||
<button
|
||||
type="button"
|
||||
className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground mt-1 transition-colors"
|
||||
>
|
||||
<Heart
|
||||
className={`h-3 w-3 ${comment.liked ? "fill-red-500 text-red-500" : ""}`}
|
||||
/>
|
||||
{comment.likeCount}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<PostComments initialComments={comments} postId={id} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { mockPosts } from "@/lib/mock"
|
||||
import { mockOrders, mockPosts } from "@/lib/mock"
|
||||
import { useRequireAuth } from "@/lib/use-require-auth"
|
||||
|
||||
const postSchema = z.object({
|
||||
@@ -37,6 +37,7 @@ export default function NewPostPage() {
|
||||
const [selectedTags, setSelectedTags] = useState<string[]>([])
|
||||
const [imageCount, setImageCount] = useState(0)
|
||||
const [selectedQuotePostId, setSelectedQuotePostId] = useState<string | undefined>(undefined)
|
||||
const [selectedOrderId, setSelectedOrderId] = useState<string | undefined>(undefined)
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -95,12 +96,18 @@ export default function NewPostPage() {
|
||||
{postType === "show_order" && (
|
||||
<div className="space-y-2">
|
||||
<Label>关联订单</Label>
|
||||
<Select>
|
||||
<Select value={selectedOrderId} onValueChange={setSelectedOrderId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="选择要展示的订单" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ord2">英雄联盟上分陪玩 · 已完成</SelectItem>
|
||||
{mockOrders
|
||||
.filter((order) => order.status === "completed")
|
||||
.map((order) => (
|
||||
<SelectItem key={order.id} value={order.id}>
|
||||
{order.service.title} · {order.playerName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -210,7 +217,11 @@ export default function NewPostPage() {
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button type="submit" className="flex-1" disabled={isSubmitting}>
|
||||
<Button
|
||||
type="submit"
|
||||
className="flex-1"
|
||||
disabled={isSubmitting || (postType === "show_order" && !selectedOrderId)}
|
||||
>
|
||||
{isSubmitting ? "发布中..." : "发布"}
|
||||
</Button>
|
||||
<Button type="button" variant="outline" asChild>
|
||||
|
||||
Reference in New Issue
Block a user