@@ -14,13 +14,13 @@ import { StyledText } from '@components/Text/StyledText';
1414import theme from '@styles/theme' ;
1515import Loading from '@components/Loading' ;
1616import Modal from '@components/Modal' ;
17- import CommentItem from './CommentItem' ;
18- import MenuButtonList from './MenuButtonList' ;
17+ import CommentItem from './CommentItem/index ' ;
18+ import MenuButtonList from './MenuButtonList/index ' ;
1919
20- import { LikeCommentBottomSheetProps } from '../dto' ;
21- import { ModalProps } from '@components/Modal/dto' ;
22- import { GetPostLikeListResponse } from '@apis/post-like/dto' ;
23- import { Comment , GetCommentListResponse } from '@apis/post-comment/dto' ;
20+ import type { LikeCommentBottomSheetProps } from '../dto' ;
21+ import type { ModalProps } from '@components/Modal/dto' ;
22+ import type { GetPostLikeListResponse } from '@apis/post-like/dto' ;
23+ import type { Comment , GetCommentListResponse } from '@apis/post-comment/dto' ;
2424
2525import Delete from '@assets/default/delete.svg' ;
2626import Block from '@assets/default/block.svg' ;
@@ -36,15 +36,11 @@ import { getCurrentUserId } from '@utils/getCurrentUserId';
3636
3737const LikeCommentBottomSheetContent : React . FC < LikeCommentBottomSheetProps > = ( { tab, likeCount, commentCount } ) => {
3838 const [ activeTab , setActiveTab ] = useState < 'likes' | 'comments' > ( tab ) ;
39- const { postId } = useParams < { postId : string } > ( ) ;
4039
4140 const [ likes , setLikes ] = useState < GetPostLikeListResponse [ 'data' ] [ 'likes' ] > ( [ ] ) ;
4241 const [ postLikeCount , setPostLikeCount ] = useState ( likeCount ) ;
4342 const [ comments , setComments ] = useState < GetCommentListResponse [ 'data' ] [ 'comments' ] > ( [ ] ) ;
4443 const [ postCommentCount , setPostCommentCount ] = useState ( commentCount ) ;
45- const [ isBlockConfirmationModalOpen , setIsBlockConfirmationModalOpen ] = useState ( false ) ;
46- const [ isStatusModalOpen , setIsStatusModalOpen ] = useState ( false ) ;
47- const [ modalContent , setModalContent ] = useState ( '알 수 없는 오류입니다.\n관리자에게 문의해 주세요.' ) ;
4844
4945 const [ isLoading , setIsLoading ] = useState ( false ) ;
5046 const [ page , setPage ] = useState ( 1 ) ;
@@ -60,50 +56,43 @@ const LikeCommentBottomSheetContent: React.FC<LikeCommentBottomSheetProps> = ({
6056 const [ isMenuVisible , setIsMenuVisible ] = useState ( false ) ;
6157 const [ menuPosition , setMenuPosition ] = useState < { top : number ; left : number } > ( { top : 0 , left : 0 } ) ;
6258
59+ const [ isBlockConfirmationModalOpen , setIsBlockConfirmationModalOpen ] = useState ( false ) ;
60+ const [ isStatusModalOpen , setIsStatusModalOpen ] = useState ( false ) ;
6361 const [ isCommentDeleteConfirmationModalOpen , setIsCommentDeleteConfirmationModalOpen ] = useRecoilState (
6462 IsCommentDeleteConfirmationModalOpenAtom ,
6563 ) ;
6664 const [ , setIsCommentReportModalOpen ] = useRecoilState ( IsCommentReportModalOpenAtom ) ;
65+ const [ modalContent , setModalContent ] = useState ( '알 수 없는 오류입니다.\n관리자에게 문의해 주세요.' ) ;
6766
67+ const { postId } = useParams < { postId : string } > ( ) ;
6868 const nav = useNavigate ( ) ;
6969
70- useEffect ( ( ) => {
71- setPage ( 1 ) ;
72- setReachedEnd ( false ) ;
73- setLikes ( [ ] ) ;
74- setComments ( [ ] ) ;
75-
76- if ( activeTab === 'likes' ) {
77- getPostLikeList ( 1 ) ;
78- } else if ( activeTab === 'comments' ) {
79- getPostCommentList ( ) ;
80- }
81- } , [ activeTab ] ) ;
82-
83- // IntersectionObserver를 활용하여 무한 스크롤 감지
84- useEffect ( ( ) => {
85- if ( observerRef . current ) observerRef . current . disconnect ( ) ;
86-
87- const handleIntersection = ( entries : IntersectionObserverEntry [ ] ) => {
88- const [ entry ] = entries ;
89- if ( entry . isIntersecting && ! isLoading ) {
90- console . log ( '호출' ) ;
91- getPostLikeList ( page ) ;
92- }
93- } ;
70+ // 댓글 메뉴 클릭한 경우
71+ const handleMenuOpen = ( comment : Comment , event : React . MouseEvent < HTMLButtonElement > ) => {
72+ setSelectedComment ( comment ) ;
73+ const rect = event . currentTarget . getBoundingClientRect ( ) ;
74+ setMenuPosition ( { top : rect . bottom + window . scrollY - 90 , left : rect . left + window . scrollX - 100 } ) ;
75+ setIsMenuVisible ( true ) ;
76+ } ;
9477
95- observerRef . current = new IntersectionObserver ( handleIntersection , {
96- root : null ,
97- rootMargin : '0px' ,
98- threshold : 1.0 ,
99- } ) ;
78+ // 유저 클릭한 경우
79+ const handleUserClick = ( userId : number ) => {
80+ // 로컬 스토리지에서 사용자 ID 가져오기
81+ const myUserId = getCurrentUserId ( ) ; // 로컬 스토리지에 저장된 사용자 ID를 가져옴
10082
101- if ( loadMoreRef . current ) observerRef . current . observe ( loadMoreRef . current ) ;
83+ if ( String ( myUserId ) === String ( userId ) ) {
84+ // 나인 경우
85+ nav ( `/profile/${ userId } ` ) ;
86+ } else {
87+ // 다른 유저인 경우
88+ nav ( `/users/${ userId } ` ) ;
89+ }
90+ } ;
10291
103- return ( ) => {
104- if ( observerRef . current ) observerRef . current . disconnect ( ) ;
105- } ;
106- } , [ page , reachedEnd , loadMoreRef . current , activeTab ] ) ;
92+ // 댓글 작성 Input
93+ const handleInputChange = useCallback ( ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
94+ setInputValue ( e . target . value ) ;
95+ } , [ ] ) ;
10796
10897 // 좋아요 리스트 불러오기 api
10998 const getPostLikeList = async ( currentPage : number ) => {
@@ -156,11 +145,6 @@ const LikeCommentBottomSheetContent: React.FC<LikeCommentBottomSheetProps> = ({
156145 }
157146 } ;
158147
159- // 댓글 작성 Input
160- const handleInputChange = useCallback ( ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
161- setInputValue ( e . target . value ) ;
162- } , [ ] ) ;
163-
164148 // 댓글 작성 api
165149 const createComment = async ( ) => {
166150 if ( isSubmitting ) return ; // 중복 요청 방지
@@ -233,6 +217,44 @@ const LikeCommentBottomSheetContent: React.FC<LikeCommentBottomSheetProps> = ({
233217 }
234218 } ;
235219
220+ useEffect ( ( ) => {
221+ setPage ( 1 ) ;
222+ setReachedEnd ( false ) ;
223+ setLikes ( [ ] ) ;
224+ setComments ( [ ] ) ;
225+
226+ if ( activeTab === 'likes' ) {
227+ getPostLikeList ( 1 ) ;
228+ } else if ( activeTab === 'comments' ) {
229+ getPostCommentList ( ) ;
230+ }
231+ } , [ activeTab ] ) ;
232+
233+ // IntersectionObserver를 활용하여 무한 스크롤 감지
234+ useEffect ( ( ) => {
235+ if ( observerRef . current ) observerRef . current . disconnect ( ) ;
236+
237+ const handleIntersection = ( entries : IntersectionObserverEntry [ ] ) => {
238+ const [ entry ] = entries ;
239+ if ( entry . isIntersecting && ! isLoading ) {
240+ console . log ( '호출' ) ;
241+ getPostLikeList ( page ) ;
242+ }
243+ } ;
244+
245+ observerRef . current = new IntersectionObserver ( handleIntersection , {
246+ root : null ,
247+ rootMargin : '0px' ,
248+ threshold : 1.0 ,
249+ } ) ;
250+
251+ if ( loadMoreRef . current ) observerRef . current . observe ( loadMoreRef . current ) ;
252+
253+ return ( ) => {
254+ if ( observerRef . current ) observerRef . current . disconnect ( ) ;
255+ } ;
256+ } , [ page , reachedEnd , loadMoreRef . current , activeTab ] ) ;
257+
236258 // 본인 댓글 메뉴 항목
237259 const MyCommentMenuItems = [
238260 {
@@ -307,28 +329,6 @@ const LikeCommentBottomSheetContent: React.FC<LikeCommentBottomSheetProps> = ({
307329 } ,
308330 } ;
309331
310- // 댓글 메뉴 클릭한 경우
311- const handleMenuOpen = ( comment : Comment , event : React . MouseEvent < HTMLButtonElement > ) => {
312- setSelectedComment ( comment ) ;
313- const rect = event . currentTarget . getBoundingClientRect ( ) ;
314- setMenuPosition ( { top : rect . bottom + window . scrollY - 90 , left : rect . left + window . scrollX - 100 } ) ;
315- setIsMenuVisible ( true ) ;
316- } ;
317-
318- // 유저 클릭한 경우
319- const handleUserClick = ( userId : number ) => {
320- // 로컬 스토리지에서 사용자 ID 가져오기
321- const myUserId = getCurrentUserId ( ) ; // 로컬 스토리지에 저장된 사용자 ID를 가져옴
322-
323- if ( String ( myUserId ) === String ( userId ) ) {
324- // 나인 경우
325- nav ( `/profile/${ userId } ` ) ;
326- } else {
327- // 다른 유저인 경우
328- nav ( `/users/${ userId } ` ) ;
329- }
330- } ;
331-
332332 return (
333333 < >
334334 < TabContainer >
0 commit comments