diff --git a/src/components/community/PostDetailIndex.tsx b/src/components/community/PostDetailIndex.tsx index d617455..c9b57bc 100644 --- a/src/components/community/PostDetailIndex.tsx +++ b/src/components/community/PostDetailIndex.tsx @@ -33,7 +33,7 @@ const PostDetailIndex = () => { {/* 구분선 */}
{/* 댓글자리 */} - + {/* 댓글입력자리 */} {open ? : ''} diff --git a/src/components/community/comments/CommentsLayout.tsx b/src/components/community/comments/CommentsLayout.tsx index ad7a131..0281dc7 100644 --- a/src/components/community/comments/CommentsLayout.tsx +++ b/src/components/community/comments/CommentsLayout.tsx @@ -2,15 +2,12 @@ import React, { Fragment, useCallback, useEffect, useRef } from 'react'; import CommentsItem from './CommentsItem'; import { CommentDataType } from '../model/commentType'; -import { useRouter } from 'next/router'; import { useInfiniteQuery } from 'react-query'; import { getAllComments } from '../remote/comment'; import useIntersectionObserver from '../hooks/useIntersectionObserver'; import Loader from '../shared/Loader'; -const CommentsLayout = () => { - const router = useRouter(); - const { id } = router.query as { id: string }; +const CommentsLayout = ({ postId }: { postId: string }) => { const ref = useRef(null); const pageRef = useIntersectionObserver(ref, {}); const isPageEnd = pageRef?.isIntersecting ?? false; @@ -22,13 +19,13 @@ const CommentsLayout = () => { isFetching, isFetchingNextPage } = useInfiniteQuery( - ['AllComments', id], - ({ pageParam }) => getAllComments({ postId: id, cursorId: pageParam }), + ['AllComments', postId], + ({ pageParam }) => getAllComments({ postId: postId, cursorId: pageParam }), { getNextPageParam: (lastPage) => { return lastPage.hasNext ? lastPage.lastVisible : undefined; }, - enabled: !!id + enabled: !!postId } ); @@ -65,7 +62,7 @@ const CommentsLayout = () => { {allComments?.length > 0 ? ( allComments?.map((comment: CommentDataType, i) => ( - + {i < allComments.length - 1 && (
)} diff --git a/src/components/community/comments/WriteCommentLayout.tsx b/src/components/community/comments/WriteCommentLayout.tsx index bca68c0..2c879c4 100644 --- a/src/components/community/comments/WriteCommentLayout.tsx +++ b/src/components/community/comments/WriteCommentLayout.tsx @@ -6,7 +6,7 @@ import Image from 'next/image'; const WriteCommentLayout = ({ postId }: { postId: string }) => { const queryClient = useQueryClient(); - const { imageUrl } = useMember(); + const { imageUrl } = useMember() as { imageUrl: string }; const [commentValue, setCommentValue] = useState(''); const textareaRef = useRef(null); @@ -37,7 +37,7 @@ const WriteCommentLayout = ({ postId }: { postId: string }) => {
image { try { - const response = await getRequest( - `posts/${postId}/comments${cursorId != null ? `?cursorId=${cursorId}` : ''}` - ); - const lastComment = response?.data?.content?.[response?.data?.content.length - 1]; - const lastVisible = lastComment ? lastComment.commentId : undefined; + let url = `posts/${postId}/comments`; + const params = []; + + if (cursorId != null) { + params.push(`cursorId=${cursorId}`); + } + + if (params.length > 0) { + url += `?${params.join('&')}`; + } + + const response = await getRequest(url); + const lastVisible = + response?.data?.content?.[response?.data?.content.length - 1]?.commentId; + return { content: response?.data?.content, lastVisible, @@ -43,13 +52,6 @@ export const deleteComment = async ({ postId, commentId }: deleteCommentType) => } catch (error: any) { return error.response.data; } - - const { data } = await axios.delete( - `http://localhost:3000/api/community/${postId}/comments/${commentId}` - ); - console.log('삭제완료'); - - return data; }; export const postComment = async ({ postId, content }: postCommentType) => { diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 72b761f..f782bc7 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -4,7 +4,7 @@ import '@/styles/globals.css'; import type { AppProps } from 'next/app'; import Script from 'next/script'; import { QueryClient, QueryClientProvider } from 'react-query'; - +import { ReactQueryDevtools } from 'react-query/devtools'; const queryClient = new QueryClient(); @@ -12,12 +12,12 @@ export default function App({ Component, pageProps }: AppProps) { return ( - + +