refactor: 重构并修复博客相关API
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { BlogApi } from "@/lib/api";
|
||||
import { BlogAPI } from "@/lib/api/client";
|
||||
import { BlogComment } from "@/lib/types/blogComment";
|
||||
import { Send, Undo2 } from "lucide-react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
@@ -34,7 +34,7 @@ export function BlogCommentTool({ blogId, onInsertComment, replayTarget, handleC
|
||||
if (comment.trim().length === 0) return;
|
||||
|
||||
try {
|
||||
const res = await BlogApi.createComment(blogId, comment, replayTarget ? replayTarget.id : undefined);
|
||||
const res = await BlogAPI.createComment(blogId, comment, replayTarget ? replayTarget.id : undefined);
|
||||
if (res) {
|
||||
toast.success('发布成功');
|
||||
setComment('');
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
'use client';
|
||||
import useSWR from "swr";
|
||||
import { BlogCommentTool } from "./BlogCommentTool";
|
||||
import { BlogApi } from "@/lib/api";
|
||||
import { BlogComment } from "@/lib/types/blogComment";
|
||||
import { useState } from "react";
|
||||
import { useUserMe } from "@/hooks/user/use-user-me";
|
||||
import { BlogAPI } from "@/lib/api/client";
|
||||
import { useUserStore } from "@/store/useUserStore";
|
||||
|
||||
export function BlogComments({ blogId }: { blogId: string }) {
|
||||
const { data, mutate } = useSWR(
|
||||
`/api/blog/${blogId}/comments`,
|
||||
() => BlogApi.getComments(blogId),
|
||||
() => BlogAPI.getComments(blogId),
|
||||
)
|
||||
|
||||
const { user } = useUserMe();
|
||||
const { user } = useUserStore();
|
||||
|
||||
const insertComment = async (newOne: BlogComment) => {
|
||||
await mutate(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { BlogApi } from "@/lib/api";
|
||||
import { base62 } from "@/lib/utils";
|
||||
import { useParams, useSearchParams } from "next/navigation";
|
||||
import useSWR from "swr";
|
||||
@@ -14,6 +13,7 @@ import rehypeRaw from 'rehype-raw'
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { BlogComments } from "./components/BlogComments";
|
||||
import Image from "next/image";
|
||||
import { BlogAPI } from "@/lib/api/client";
|
||||
|
||||
export default function Blog() {
|
||||
const params = useParams();
|
||||
@@ -31,9 +31,7 @@ export default function Blog() {
|
||||
const password = searchParams.get('p');
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/api/blog/${id}`,
|
||||
() => BlogApi.get(id, {
|
||||
password: password || undefined,
|
||||
}),
|
||||
() => BlogAPI.getBlog(id, password || undefined),
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user