Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

챌린지 상세보기 페이지 이동 기능 구현 #173

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/apis/challenge-record/challenge.record.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function postVerification(
id: number,
image: File,
content: string
): Promise<ChallengeVerificationData> {
): Promise<{ data: ChallengeVerificationData; status: number }> {
const formData = new FormData();
formData.append(
'body',
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/pages/challenge-list/components/contents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type Props = {
startDate: string;
endDate: string;
participantCount: number;
id: number;
onClick: (id: number) => void;
};

const Contents = ({
Expand All @@ -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}`;
Expand Down
9 changes: 9 additions & 0 deletions src/pages/challenge-list/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -23,6 +24,12 @@ const ChallengeList = () => {
const [allData, setAllData] = useState<Challenge[]>([]);
const [page, setPage] = useState(0);

const navigate = useNavigate();

const handleNavigate = (id: number) => {
navigate(`/challenge/${id}`);
};

const categoryList = useMemo(
() => [
{ label: '에코', data: 'ECHO' },
Expand Down Expand Up @@ -102,6 +109,8 @@ const ChallengeList = () => {
startDate={challenge.startDate}
endDate={challenge.endDate}
participantCount={challenge.participantCount}
onClick={() => handleNavigate(challenge.id)}
id={challenge.id}
/>
))}
</>
Expand Down
6 changes: 4 additions & 2 deletions src/pages/shorts/components/info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<ShortsInfoLayout>
Expand All @@ -36,7 +38,7 @@ const ShortsInfo = ({ info }: Props) => {
: '정보 없음'}
</Text>
</Box>
<ShortsStartBox>
<ShortsStartBox onClick={() => onClick(id)}>
<Image width='1rem' height='1.25rem' src={StartIcon} />
</ShortsStartBox>
</ShortsInfoTextBox>
Expand Down
18 changes: 16 additions & 2 deletions src/pages/shorts/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -33,7 +35,8 @@ const Shorts = () => {
const [allData, setAllData] = useState<Short[]>([]);
const { data, isLoading } = useGetShorts(page, 20);

console.log(data);
const navigate = useNavigate();

useEffect(() => {
if (data) {
setAllData((prevData) => [...prevData, ...data.data.data]);
Expand All @@ -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 (
<>
<TopBar type='Page' title='' backgroundColor='var(--color--green-06)' />
Expand All @@ -81,7 +91,11 @@ const Shorts = () => {
<ShortsContents title={item.title} content={item.content} />
<ShortsImage />
{infoData && infoData[index] && (
<ShortsInfo info={infoData[index]} />
<ShortsInfo
onClick={() => handleNavigate(infoData[index].id)}
id={infoData[index].id}
info={infoData[index]}
/>
)}
</SwiperSlide>
))}
Expand Down