@@ -8,6 +8,8 @@ import ChallengeContent from '@/components/Challenge/ChallengeContent';
88import Header from '@/components/shared/Header' ;
99import { ChallengeType , ChallengeFilter } from '@/types/Challenge' ;
1010import { useGetChallenge } from '@/service/Challenge/challenge.query' ;
11+ import { useGetBookmarkList } from '@/service/shared/shared.query' ;
12+ import { useBookmark } from '@/hooks/useBookmark' ;
1113import Loading from '@/components/shared/Loading' ;
1214
1315const challengeCategories = [
@@ -75,6 +77,43 @@ const Challenge = () => {
7577 } ;
7678
7779 const { data : ChallengeData , isPending } = useGetChallenge ( filterParams ) ;
80+ const { data : bookmarkData } = useGetBookmarkList ( ) ;
81+
82+ // 북마크된 챌린지 ID들을 배열로 저장
83+ const bookmarkedChallengeIds =
84+ bookmarkData ?. data ?. map (
85+ ( bookmark : { challengeId : number } ) => bookmark . challengeId
86+ ) || [ ] ;
87+
88+ // 개별 챌린지의 북마크 기능을 위한 컴포넌트
89+ const ChallengeWithBookmark = ( {
90+ challenge,
91+ } : {
92+ challenge : ChallengeType ;
93+ } ) => {
94+ const isInitiallyBookmarked = bookmarkedChallengeIds . includes ( challenge . id ) ;
95+ const { isBookmarked, toggleBookmark, isLoading } = useBookmark ( {
96+ challengeId : challenge . id ,
97+ initialBookmarkState : isInitiallyBookmarked ,
98+ } ) ;
99+
100+ return (
101+ < ChallengeContent
102+ key = { challenge . id }
103+ id = { challenge . id }
104+ count = { challenge . participantCount }
105+ title = { challenge . title }
106+ imgUrl = { challenge . imgURL }
107+ days = { Number ( challenge . day ) }
108+ difficulty = { challenge . difficulty }
109+ createrName = { challenge . User . name }
110+ createrImgUrl = { challenge . User . profileImg }
111+ isChecked = { isBookmarked }
112+ onClickBookmark = { toggleBookmark }
113+ isBookmarkLoading = { isLoading }
114+ />
115+ ) ;
116+ } ;
78117
79118 const hasActiveFilters = Object . values ( filters ) . some (
80119 ( v ) => v !== '전체' && v !== '인기순'
@@ -156,17 +195,7 @@ const Challenge = () => {
156195 < div className = "flex-1 h-0 min-h-0 px-8 pb-16 mt-2 overflow-y-scroll scrollbar-hide -webkit-overflow-scrolling-touch overscroll-contain" >
157196 < div className = "grid grid-cols-2 gap-x-5 gap-y-5" >
158197 { ChallengeData ?. data ?. challenges ?. map ( ( item : ChallengeType ) => (
159- < ChallengeContent
160- key = { item . id }
161- id = { item . id }
162- count = { item . participantCount }
163- title = { item . title }
164- imgUrl = { item . imgURL }
165- days = { Number ( item . day ) }
166- difficulty = { item . difficulty }
167- createrName = { item . User . name }
168- createrImgUrl = { item . User . profileImg }
169- />
198+ < ChallengeWithBookmark key = { item . id } challenge = { item } />
170199 ) ) }
171200 </ div >
172201 </ div >
0 commit comments