实现评论本地更新

This commit is contained in:
2025-06-07 13:49:33 +08:00
parent 3821ef6657
commit 73e409ce84
5 changed files with 35 additions and 24 deletions

View File

@@ -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<BlogComment>(`/api/blog/${blogId}/comment`, {
method: 'POST',
body: JSON.stringify({ content }),
});

View File

@@ -1,13 +1,6 @@
import { BlogComment } from "@/lib/types/blogComment";
import fetcher from "../fetcher";
export async function getComments(blogId: string) {
return fetcher<{
blogId: string;
content: string;
createdAt: string;
deletedAt: string | null;// 原则上能看到就是null
id: string;
parentId: string | null; // 如果是回复则有parentId
user: null;// TODO需要完善
}[]>(`/api/blog/${blogId}/comments`, { method: 'GET' });
return fetcher<BlogComment[]>(`/api/blog/${blogId}/comments`, { method: 'GET' });
}

View File

@@ -0,0 +1,11 @@
import { User } from "./user";
export interface BlogComment {
id: string;
blogId: string;
content: string;
createdAt: string;
deletedAt: string | null;
parentId: string | null;
user: User | null;
}