@@ -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