diff --git a/src/apis/Board/BoardPostLikeApi.ts b/src/apis/Board/BoardPostLikeApi.ts index e890919..fca3ccd 100644 --- a/src/apis/Board/BoardPostLikeApi.ts +++ b/src/apis/Board/BoardPostLikeApi.ts @@ -2,7 +2,7 @@ import { createRequestOptionsJSON_AUTH, fetchApi } from "@/apis/_createRequestOp interface PostLikeOnPostApiResponseType { code: number; - status: number; + status: string; message: string; result: string; } diff --git a/src/pages/BoardPage/BoardDetailpage/BoardDetailPage.tsx b/src/pages/BoardPage/BoardDetailpage/BoardDetailPage.tsx index 8510804..71979cb 100644 --- a/src/pages/BoardPage/BoardDetailpage/BoardDetailPage.tsx +++ b/src/pages/BoardPage/BoardDetailpage/BoardDetailPage.tsx @@ -212,39 +212,13 @@ const BoardDetailPage = () => { const spaceId = localStorage.getItem("spaceId"); - useEffect(() => { - if (spaceId !== null) { - getPostDetailApi(Number.parseInt(spaceId), Number.parseInt(id || "0")) - .then((res) => { - if (res === null) { - setPostsData(undefined); - } else { - setPostsData(res.result); - setIsLikeNew(res.result.like); - setLikeCountNew(res.result.likeCount); - } - }) - .catch((err) => { - console.error(err); - setPostsData(undefined); - }); - getPostCommentApi(Number.parseInt(spaceId), Number.parseInt(id || "0")) - .then((res) => { - if (res !== null) { - setCommentsData(res.result); - } - }) - .catch((err) => console.log(err)); - } - }, [newCommentCount]); - const handleLike = () => { if (spaceId !== null && postsData !== undefined) { - if (postsData.like === true) { + if (isLikeNew === true) { // 좋아요 해제 deleteLikeOnPostApi(Number.parseInt(spaceId), postsData.postId) .then((res) => { - if (res !== null) { + if (res?.status === "OK") { setIsLikeNew(false); setLikeCountNew((prev) => prev - 1); } @@ -255,7 +229,7 @@ const BoardDetailPage = () => { } else { postLikeOnPostApi(Number.parseInt(spaceId), postsData.postId) .then((res) => { - if (res !== null) { + if (res?.status === "OK") { setIsLikeNew(true); setLikeCountNew((prev) => prev + 1); } @@ -267,6 +241,32 @@ const BoardDetailPage = () => { } }; + useEffect(() => { + if (spaceId !== null) { + getPostDetailApi(Number.parseInt(spaceId), Number.parseInt(id || "0")) + .then((res) => { + if (res === null) { + setPostsData(undefined); + } else { + setPostsData(res.result); + setIsLikeNew(res.result.like); + setLikeCountNew(res.result.likeCount); + } + }) + .catch((err) => { + console.error(err); + setPostsData(undefined); + }); + getPostCommentApi(Number.parseInt(spaceId), Number.parseInt(id || "0")) + .then((res) => { + if (res !== null) { + setCommentsData(res.result); + } + }) + .catch((err) => console.log(err)); + } + }, [newCommentCount]); + const handleRegisterComment = () => { if (spaceId !== null && postsData !== undefined) { createPostCommentApi(Number.parseInt(spaceId), postsData?.postId, commentValue) diff --git a/src/pages/BoardPage/BoardPostItem.tsx b/src/pages/BoardPage/BoardPostItem.tsx index b6e1949..184d682 100644 --- a/src/pages/BoardPage/BoardPostItem.tsx +++ b/src/pages/BoardPage/BoardPostItem.tsx @@ -174,11 +174,11 @@ const BoardPostItem = ({ const handleLike = () => { if (spaceId !== null) { - if (isLike === true) { + if (isLikeNew === true) { // 좋아요 해제 deleteLikeOnPostApi(Number.parseInt(spaceId), postId) .then((res) => { - if (res !== null) { + if (res?.status === "OK") { setIsLikeNew(false); setLikeCountNew((prev) => prev - 1); } @@ -189,7 +189,7 @@ const BoardPostItem = ({ } else { postLikeOnPostApi(Number.parseInt(spaceId), postId) .then((res) => { - if (res !== null) { + if (res?.status === "OK") { setIsLikeNew(true); setLikeCountNew((prev) => prev + 1); } @@ -224,7 +224,7 @@ const BoardPostItem = ({