"use client" import { standardSchemaResolver } from "@hookform/resolvers/standard-schema" import { ArrowLeft, ImagePlus, X } from "lucide-react" import Link from "next/link" import { useRouter } from "next/navigation" import { useState } from "react" import { useForm } from "react-hook-form" import { z } from "zod" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" import { mockPosts } from "@/lib/mock" import { useRequireAuth } from "@/lib/use-require-auth" const postSchema = z.object({ title: z.string().min(2, "标题至少2个字符").max(50, "标题最多50个字符"), content: z.string().min(10, "内容至少10个字符"), }) const tagOptions = ["英雄联盟", "王者荣耀", "CS2", "原神", "上分", "攻略", "好评", "吐槽", "求组队"] export default function NewPostPage() { const router = useRouter() const { isAuthenticated, requireAuth } = useRequireAuth() const [postType, setPostType] = useState("normal") const [selectedTags, setSelectedTags] = useState([]) const [imageCount, setImageCount] = useState(0) const [selectedQuotePostId, setSelectedQuotePostId] = useState(undefined) const { register, handleSubmit, formState: { errors, isSubmitting }, } = useForm({ resolver: standardSchemaResolver(postSchema), }) const toggleTag = (tag: string) => { setSelectedTags((prev) => prev.includes(tag) ? prev.filter((t) => t !== tag) : prev.length < 5 ? [...prev, tag] : prev, ) } const onSubmit = async () => { if (!isAuthenticated) { requireAuth(() => undefined) return } await new Promise((r) => setTimeout(r, 500)) router.push("/community") } return (
返回社区 发布帖子
{postType === "show_order" && (
)} {postType === "quote" && (

预览:

{selectedQuotePostId ? ( (() => { const post = mockPosts.find((p) => p.id === selectedQuotePostId) if (!post) return

未找到帖子

return (

{post.title}

{post.content}

@{post.author.nickname} · {new Date(post.createdAt).toLocaleDateString("zh-CN")}
) })() ) : (

选择一个帖子以查看预览...

)}
)}
{errors.title &&

{errors.title.message}

}