From 73e409ce84c886b3b357ce2c9025a48af9c7bdb1 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Sat, 7 Jun 2025 13:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=AF=84=E8=AE=BA=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/[id]/components/BlogCommentTool.tsx | 8 +++++--- .../blog/[id]/components/BlogComments.tsx | 19 +++++++++++++++---- tone-page-web/lib/api/blog/createComment.ts | 10 ++-------- tone-page-web/lib/api/blog/getComments.ts | 11 ++--------- tone-page-web/lib/types/blogComment.ts | 11 +++++++++++ 5 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 tone-page-web/lib/types/blogComment.ts diff --git a/tone-page-web/app/(with-header-footer)/blog/[id]/components/BlogCommentTool.tsx b/tone-page-web/app/(with-header-footer)/blog/[id]/components/BlogCommentTool.tsx index e73cd04..46f01e3 100644 --- a/tone-page-web/app/(with-header-footer)/blog/[id]/components/BlogCommentTool.tsx +++ b/tone-page-web/app/(with-header-footer)/blog/[id]/components/BlogCommentTool.tsx @@ -3,26 +3,28 @@ import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { BlogApi } from "@/lib/api"; +import { BlogComment } from "@/lib/types/blogComment"; import { Send } from "lucide-react"; import { useState } from "react"; import { toast } from "sonner"; -export function BlogCommentTool({ blogId }: { blogId: string }) { +export function BlogCommentTool({ blogId, onInsertComment }: { blogId: string, onInsertComment: (b: BlogComment) => void }) { const [comment, setComment] = useState(''); const submit = async () => { + if (comment.trim().length === 0) return; const res = await BlogApi.createComment(blogId, comment); if (res) { toast.success('发布成功'); setComment(''); - // 提交界面刷新 + onInsertComment(res); } } return (
{new Date(d.createdAt).toLocaleString()}
@@ -30,7 +41,7 @@ export function BlogComments({ blogId }: { blogId: string }) { { data.filter(c => c.parentId === d.id).map(c => (
{new Date().toLocaleString()}
diff --git a/tone-page-web/lib/api/blog/createComment.ts b/tone-page-web/lib/api/blog/createComment.ts index e4655b8..f2f9e5b 100644 --- a/tone-page-web/lib/api/blog/createComment.ts +++ b/tone-page-web/lib/api/blog/createComment.ts @@ -1,14 +1,8 @@ +import { BlogComment } from "@/lib/types/blogComment"; import fetcher from "../fetcher"; export async function createComment(blogId: string, content: string) { - return fetcher<{ - blogId: string; - content: string; - createdAt: string - deletedAt: null; // 原则上能看到就是null - id: string; - parentId: string | null; - }>(`/api/blog/${blogId}/comment`, { + return fetcher