diff --git a/src/apis/challenge-record/challenge.record.api.ts b/src/apis/challenge-record/challenge.record.api.ts index c6578e7..a788695 100644 --- a/src/apis/challenge-record/challenge.record.api.ts +++ b/src/apis/challenge-record/challenge.record.api.ts @@ -12,7 +12,7 @@ export async function postVerification( id: number, image: File, content: string -): Promise { +): Promise<{ data: ChallengeVerificationData; status: number }> { const formData = new FormData(); formData.append( 'body', @@ -25,7 +25,8 @@ export async function postVerification( formData ); console.log('postVerification response: ', response.data); - return response.data; + // return response.data; + return { data: response.data, status: response.status }; } // GET: /api/challenges/{challengeId}/record diff --git a/src/pages/challenge-list/components/contents/index.tsx b/src/pages/challenge-list/components/contents/index.tsx index 2aa0b64..b9e4f11 100644 --- a/src/pages/challenge-list/components/contents/index.tsx +++ b/src/pages/challenge-list/components/contents/index.tsx @@ -9,6 +9,8 @@ type Props = { startDate: string; endDate: string; participantCount: number; + id: number; + onClick: (id: number) => void; }; const Contents = ({ @@ -17,11 +19,14 @@ const Contents = ({ startDate, endDate, participantCount, + onClick, + id, }: Props) => { const [isClicked, setIsClicked] = useState(false); const handleBoxClick = () => { setIsClicked(!isClicked); + onClick(id); }; const date = `${startDate} ~ ${endDate}`; diff --git a/src/pages/challenge-list/index.tsx b/src/pages/challenge-list/index.tsx index 4ea2249..8d0da1c 100644 --- a/src/pages/challenge-list/index.tsx +++ b/src/pages/challenge-list/index.tsx @@ -1,4 +1,5 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; +import { useNavigate } from 'react-router-dom'; import Contents from './components/contents'; import { useGetChallengeList } from '@/apis/challenge-list/getChallengeList.api'; @@ -23,6 +24,12 @@ const ChallengeList = () => { const [allData, setAllData] = useState([]); const [page, setPage] = useState(0); + const navigate = useNavigate(); + + const handleNavigate = (id: number) => { + navigate(`/challenge/${id}`); + }; + const categoryList = useMemo( () => [ { label: '에코', data: 'ECHO' }, @@ -102,6 +109,8 @@ const ChallengeList = () => { startDate={challenge.startDate} endDate={challenge.endDate} participantCount={challenge.participantCount} + onClick={() => handleNavigate(challenge.id)} + id={challenge.id} /> ))} diff --git a/src/pages/shorts/components/info/index.tsx b/src/pages/shorts/components/info/index.tsx index b0247ae..e2df693 100644 --- a/src/pages/shorts/components/info/index.tsx +++ b/src/pages/shorts/components/info/index.tsx @@ -10,9 +10,11 @@ type Info = { type Props = { info?: Info; + onClick: (id: number) => void; + id: number; }; -const ShortsInfo = ({ info }: Props) => { +const ShortsInfo = ({ info, id, onClick }: Props) => { return ( <> @@ -36,7 +38,7 @@ const ShortsInfo = ({ info }: Props) => { : '정보 없음'} - + onClick(id)}> diff --git a/src/pages/shorts/index.tsx b/src/pages/shorts/index.tsx index 7323566..e67b4eb 100644 --- a/src/pages/shorts/index.tsx +++ b/src/pages/shorts/index.tsx @@ -1,4 +1,5 @@ import { useEffect, useState } from 'react'; +import { useNavigate } from 'react-router-dom'; import ShortsContents from './components/contents'; import ShortsImage from './components/image'; @@ -13,6 +14,7 @@ import { Mousewheel, Pagination } from 'swiper/modules'; import { Swiper, SwiperSlide } from 'swiper/react'; type Short = { + id: number; title: string; content: string; participantCount: number; @@ -33,7 +35,8 @@ const Shorts = () => { const [allData, setAllData] = useState([]); const { data, isLoading } = useGetShorts(page, 20); - console.log(data); + const navigate = useNavigate(); + useEffect(() => { if (data) { setAllData((prevData) => [...prevData, ...data.data.data]); @@ -48,18 +51,25 @@ const Shorts = () => { const contentsData = shuffleArray( allData.map((item) => ({ + id: item.id, title: item.title, content: item.content, })) ); + const handleNavigate = (id: number) => { + navigate(`/challenge/${id}`); + }; + const infoData = shuffleArray( allData.map((item) => ({ participantCount: item.participantCount, category: item.category, + id: item.id, })) ); + console.log(data?.data.data); return ( <> @@ -81,7 +91,11 @@ const Shorts = () => { {infoData && infoData[index] && ( - + handleNavigate(infoData[index].id)} + id={infoData[index].id} + info={infoData[index]} + /> )} ))}