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 = ({
setIsLikeNew((prev) => !prev)} + // onClick={() => setIsLikeNew((prev) => !prev)} > 좋아요 {likeCountNew} diff --git a/src/pages/BoardPage/BoardRegisterPage/BoardRegisterPage.tsx b/src/pages/BoardPage/BoardRegisterPage/BoardRegisterPage.tsx index 5a2d153..76b860e 100644 --- a/src/pages/BoardPage/BoardRegisterPage/BoardRegisterPage.tsx +++ b/src/pages/BoardPage/BoardRegisterPage/BoardRegisterPage.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; +import { useNavigate } from "react-router-dom"; import styled from "styled-components"; import { CreateBoardPostApi } from "@/apis/Board/BoardPostApi"; @@ -120,10 +121,9 @@ const BoardRegisterPage = () => { const [isNotice, setIsNotice] = useState(false); const [selectedImages, setSelectedImages] = useState([]); - const spaceId = localStorage.getItem("spaceId"); + const navigate = useNavigate(); - // TODO: API 연동 시 수정 예정 - const isManager = true; + const spaceId = localStorage.getItem("spaceId"); const inputRef = useRef(null); const textareaRef = useRef(null); @@ -154,6 +154,7 @@ const BoardRegisterPage = () => { ).then((res) => { if (res) { console.log("생성 완료: ", res); + navigate("/board"); } }); } @@ -175,17 +176,15 @@ const BoardRegisterPage = () => { } > - {isManager && ( - - { - setIsNotice((prev) => !prev); - console.log(isNotice); - }} - /> - 공지로 등록하기 - - )} + + { + setIsNotice((prev) => !prev); + console.log(isNotice); + }} + /> + 공지로 등록하기 +