diff --git a/src/app/community/edit/[postId]/page.tsx b/src/app/community/edit/[postId]/page.tsx index 81edd8f..e091ba3 100644 --- a/src/app/community/edit/[postId]/page.tsx +++ b/src/app/community/edit/[postId]/page.tsx @@ -6,6 +6,7 @@ import { useParams } from 'next/navigation'; function Page() { const params = useParams(); + console.log(params); return (
diff --git a/src/domains/community/detail/DetailContent.tsx b/src/domains/community/detail/DetailContent.tsx index bfec34f..5a5af01 100644 --- a/src/domains/community/detail/DetailContent.tsx +++ b/src/domains/community/detail/DetailContent.tsx @@ -39,7 +39,7 @@ function DetailContent({ -
+
state.user); + const [postDetail, setPostDetail] = useState(null); const [isLoading, setIsLoading] = useState(false); const [like, setLike] = useState(false); @@ -27,6 +30,8 @@ function DetailPage() { const isLoggedIn = useAuthStore((state) => state.isLoggedIn); const router = useRouter(); + const { comments } = useComments(postId, user); + const commentRef = useRef(null); useEffect(() => { @@ -119,7 +124,7 @@ function DetailPage() { {isLoggedIn && ( -
+
)} diff --git a/src/domains/community/detail/tab/DetailTabDesktop.tsx b/src/domains/community/detail/tab/DetailTabDesktop.tsx index 8b2987b..2106232 100644 --- a/src/domains/community/detail/tab/DetailTabDesktop.tsx +++ b/src/domains/community/detail/tab/DetailTabDesktop.tsx @@ -5,6 +5,8 @@ import CommentBtn from '../../components/comment/CommentBtn'; import LikeBtn from '../../components/like/LikeBtn'; import ShareModal from '@/domains/shared/components/share/ShareModal'; import { RefObject, useState } from 'react'; +import { useParams } from 'next/navigation'; +import { CommentType } from '../../types/post'; type Props = { likeCount: number; @@ -14,6 +16,7 @@ type Props = { onLikeToggle: () => void; title: string; imageUrls: string[]; + comments: CommentType[] | null; }; interface Meta { @@ -30,10 +33,14 @@ function DetailTabDesktop({ onLikeToggle, title, imageUrls, + comments, }: Props) { const [isShare, setIsShare] = useState(false); const [meta, setMeta] = useState(null); + const params = useParams(); + const postId = params?.id; + const handleClick = () => { if (commentRef.current) { const top = commentRef.current.getBoundingClientRect().top + window.scrollY - 100; // 100px 위로 offset @@ -43,15 +50,13 @@ function DetailTabDesktop({ // ✅ 공유 버튼 클릭 시 meta 생성 const handleShareClick = () => { - if (typeof window !== 'undefined') { - const currentUrl = window.location.href; - setMeta({ - title, - url: currentUrl, - imageUrl: imageUrls[0] || getOgImage(), - }); - setIsShare(true); - } + const currentUrl = `http://www.ssoul.life/community/${postId}`; + setMeta({ + title, + url: currentUrl, + imageUrl: imageUrls[0] || getOgImage(), + }); + setIsShare(true); }; // ✅ og:image 메타태그에서 이미지 가져오기 (fallback용) @@ -64,7 +69,7 @@ function DetailTabDesktop({ <>
@@ -74,7 +79,7 @@ function DetailTabDesktop({
- {commentCount} + {comments?.length}
diff --git a/src/domains/community/detail/tab/DetailTabMobile.tsx b/src/domains/community/detail/tab/DetailTabMobile.tsx index fffca53..1d6f85a 100644 --- a/src/domains/community/detail/tab/DetailTabMobile.tsx +++ b/src/domains/community/detail/tab/DetailTabMobile.tsx @@ -4,6 +4,7 @@ import Share from '@/domains/shared/components/share/Share'; import LikeBtn from '../../components/like/LikeBtn'; import { useState } from 'react'; import ShareModal from '@/domains/shared/components/share/ShareModal'; +import { useParams } from 'next/navigation'; type Props = { likeCount: number; @@ -23,16 +24,17 @@ function DetailTabMobile({ likeCount, onLikeToggle, like, title, imageUrls }: Pr const [isShare, setIsShare] = useState(false); const [meta, setMeta] = useState(null); + const params = useParams(); + const postId = params?.id; + const handleShareClick = () => { - if (typeof window !== 'undefined') { - const currentUrl = window.location.href; - setMeta({ - title, - url: currentUrl, - imageUrl: imageUrls[0] || getOgImage(), - }); - setIsShare(true); - } + const currentUrl = `http://www.ssoul.life/community/${postId}`; + setMeta({ + title, + url: currentUrl, + imageUrl: imageUrls[0] || getOgImage(), + }); + setIsShare(true); }; // ✅ og:image 메타태그에서 이미지 가져오기 (fallback용) diff --git a/src/domains/community/hook/useComment.ts b/src/domains/community/hook/useComment.ts index ad77a19..d94e0f9 100644 --- a/src/domains/community/hook/useComment.ts +++ b/src/domains/community/hook/useComment.ts @@ -5,7 +5,7 @@ import { CommentType } from '../types/post'; import { User } from '@/domains/shared/store/auth'; import { ParamValue } from 'next/dist/server/request/params'; -export function useComments(postId: ParamValue, user: User | null, accessToken: string | null) { +export function useComments(postId: ParamValue, user: User | null, accessToken?: string | null) { const [comments, setComments] = useState(null); const [isEnd, setIsEnd] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -23,7 +23,7 @@ export function useComments(postId: ParamValue, user: User | null, accessToken: useEffect(() => { fetchData(); - }, [fetchData]); + }, [postId]); const handleUpdateComment = async (commentId: number, content: string) => { if (!user) { @@ -39,6 +39,8 @@ export function useComments(postId: ParamValue, user: User | null, accessToken: ) : prev ); + const updatedComments = await fetchComment(postId); + setComments(updatedComments); } catch (err) { console.error(err); alert('댓글 수정 중 오류가 발생했습니다.'); @@ -61,6 +63,8 @@ export function useComments(postId: ParamValue, user: User | null, accessToken: setComments((prev) => prev ? prev.filter((c) => c.commentId !== deleteTarget.commentId) : prev ); + const updatedComments = await fetchComment(postId); + setComments(updatedComments); } catch (err) { console.error(err); alert('댓글 삭제 중 오류가 발생했습니다.'); diff --git a/src/domains/community/main/CommunityFilter.tsx b/src/domains/community/main/CommunityFilter.tsx index 25dfd90..6887752 100644 --- a/src/domains/community/main/CommunityFilter.tsx +++ b/src/domains/community/main/CommunityFilter.tsx @@ -22,10 +22,6 @@ function CommunityFilter({ posts, setPosts }: Props) { const query = searchParams.get('category'); const router = useRouter(); - useEffect(() => { - console.log(query); - }, [query]); - const handleChange = async (selectTitle: string) => { if (!query) return; diff --git a/src/domains/community/main/PostCard.tsx b/src/domains/community/main/PostCard.tsx index 755cf0d..eb79f10 100644 --- a/src/domains/community/main/PostCard.tsx +++ b/src/domains/community/main/PostCard.tsx @@ -61,7 +61,7 @@ function PostCard({ posts, isLoading, isEnd, onLoadMore }: Props) { return (
{ if (index === 0) firstItemRef.current = el; if (isLast) { diff --git a/src/domains/community/write/CompleteBtn.tsx b/src/domains/community/write/CompleteBtn.tsx index da86926..a809735 100644 --- a/src/domains/community/write/CompleteBtn.tsx +++ b/src/domains/community/write/CompleteBtn.tsx @@ -1,9 +1,22 @@ import Button from '@/shared/components/button/Button'; -function CompleteBtn({ mode }: { mode: 'edit' | 'create' }) { +type Props = { + mode: 'edit' | 'create'; + setEditDone: (value: boolean) => void; + handleEditLogic: () => Promise; +}; + +function CompleteBtn({ mode, setEditDone, handleEditLogic }: Props) { return (
-
diff --git a/src/domains/community/write/WriteForm.tsx b/src/domains/community/write/WriteForm.tsx index 3d653e6..a61ff82 100644 --- a/src/domains/community/write/WriteForm.tsx +++ b/src/domains/community/write/WriteForm.tsx @@ -16,6 +16,7 @@ function WriteForm({ formData, setFormData }: Props) {