Skip to content

Commit c222cb6

Browse files
committed
feat: 신고 모달 파라미터 변경으로 인한, 파라미터 추가(게시판 상세)
1 parent 03a1eec commit c222cb6

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

src/apis/share.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const getSharePostList = async (page: number = 1, size: number = 10) => {
5353
};
5454

5555
// 공유 게시글 상세 조회
56-
export const getSharePostDetail = async (sharePostId: number): Promise<SharePost> => {
56+
export const getSharePostDetail = async (sharePostId: string): Promise<SharePost> => {
5757
try {
5858
const response = await client.get(`/api/share-posts/${sharePostId}`);
5959
console.log(`🔥공유 게시글 상세 데이터`, response.data);
@@ -102,7 +102,7 @@ export const postShareProposalApproval = async (
102102
};
103103

104104
// 편지 좋아요 추가, 취소
105-
export const postSharePostLike = async (sharePostId: number) => {
105+
export const postSharePostLike = async (sharePostId: string) => {
106106
try {
107107
const response = await client.post(`/api/share-posts/${sharePostId}/likes`);
108108
if (!response) throw new Error('error while posting like');
@@ -114,7 +114,7 @@ export const postSharePostLike = async (sharePostId: number) => {
114114
};
115115

116116
// 편지 좋아요 갯수
117-
export const getSharePostLikeCount = async (sharePostId: number) => {
117+
export const getSharePostLikeCount = async (sharePostId: string) => {
118118
try {
119119
const response = await client.get(`/api/share-posts/${sharePostId}/likes`);
120120
if (!response) throw new Error('error while fetching likes');

src/pages/LetterBoardDetail/index.tsx

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,69 +25,85 @@ const LetterBoardDetailPage = ({ confirmDisabled }: ShareLetterPreviewProps) =>
2525
const [isLike, setIsLike] = useState(false);
2626
const isWriter = false;
2727
const [activeReportModal, setActiveReportModal] = useState(false);
28+
const sharePostId: string = location.pathname.split('/')[3];
29+
// const location = useLocation();
30+
const navigate = useNavigate();
31+
// const isShareLetterPreview = location.state?.isShareLetterPreview || false;
32+
const isShareLetterPreview = false;
33+
const [postDetail, setPostDetail] = useState<SharePost>();
34+
35+
const postLike = async () => {
36+
try {
37+
const response = await postSharePostLike(sharePostId);
38+
if (!response) throw new Error('error while fetching like count');
39+
console.log('✅ 편지 좋아요 추가됨:', response);
40+
} catch (error) {
41+
console.error('❌ 편지 좋아요 추가 중 에러가 발생했습니다', error);
42+
throw new Error('편지 좋아요 추가 실패');
43+
}
44+
};
2845

2946
const handleToggleLike = () => {
3047
setLikeCount((prev) => prev + (isLike ? -1 : 1));
3148
setIsLike((prev) => !prev);
49+
postLike();
3250
};
3351

34-
const location = useLocation();
35-
const navigate = useNavigate();
52+
const handleProposalApproval = async (
53+
action: 'approve' | 'reject',
54+
shareProposalId: number = location.state?.postDetail?.sharePostId,
55+
) => {
56+
try {
57+
const result = await postShareProposalApproval(shareProposalId, action);
58+
console.log(`✅ 편지 공유 ${action === 'approve' ? '수락' : '거절'}됨:`, result);
3659

37-
const isShareLetterPreview = location.state?.isShareLetterPreview || false;
38-
const [postDetail, setPostDetail] = useState<SharePost>();
60+
navigate('/');
61+
} catch (error) {
62+
console.error(error);
63+
}
64+
};
3965

4066
useEffect(() => {
41-
const { sharePostId } = location.state.postDetail;
42-
const fetchPostDetail = async (postId: number) => {
67+
const fetchPostDetail = async (postId: string) => {
4368
try {
44-
console.log('sharePostId:', postId);
45-
4669
const data = await getSharePostDetail(postId);
47-
4870
setPostDetail(data);
4971
} catch (error) {
5072
console.error('❌ 공유 게시글 상세 조회에 실패했습니다.', error);
5173
}
5274
};
5375

54-
const fetchLikeCounts = async (postId: number) => {
76+
const fetchLikeCounts = async (postId: string) => {
5577
try {
5678
const response = await getSharePostLikeCount(postId);
5779
if (!response) throw new Error('error while fetching like count');
58-
console.log(response);
59-
setLikeCount(response.data.likeCount);
80+
console.log('✅ 편지 좋아요 갯수:', response);
81+
setLikeCount(response.likeCount);
82+
setIsLike(response.liked);
6083
} catch (error) {
6184
console.error('❌ 편지 좋아요 갯수를 가져오는 중 에러가 발생했습니다', error);
6285
throw new Error('편지 좋아요 갯수 가져오기 실패');
6386
}
6487
};
6588

66-
if (location.state?.postDetail) {
67-
fetchPostDetail(sharePostId);
68-
fetchLikeCounts(sharePostId);
69-
} else {
70-
console.warn('postDetail not found in location.state');
71-
}
72-
}, [location.state]);
73-
74-
const handleProposalApproval = async (
75-
action: 'approve' | 'reject',
76-
shareProposalId: number = location.state?.postDetail?.sharePostId,
77-
) => {
78-
try {
79-
const result = await postShareProposalApproval(shareProposalId, action);
80-
console.log(`✅ 편지 공유 ${action === 'approve' ? '수락' : '거절'}됨:`, result);
81-
82-
navigate('/');
83-
} catch (error) {
84-
console.error(error);
85-
}
86-
};
89+
// if (location.state?.postDetail) {
90+
fetchPostDetail(sharePostId);
91+
fetchLikeCounts(sharePostId);
92+
// } else {
93+
// console.warn('postDetail not found in location.state');
94+
// }
95+
// }, [location.state]);
96+
}, []);
8797

8898
return (
8999
<>
90-
{activeReportModal && <ReportModal onClose={() => setActiveReportModal(false)} />}
100+
{activeReportModal && (
101+
<ReportModal
102+
reportType="POST"
103+
letterId={sharePostId}
104+
onClose={() => setActiveReportModal(false)}
105+
/>
106+
)}
91107
<div className="grow bg-white">
92108
<Header
93109
likeCount={likeCount}

0 commit comments

Comments
 (0)