From 312b6eaea636b3fb4e8dabf3604c3761f9b79279 Mon Sep 17 00:00:00 2001 From: joojjang Date: Wed, 2 Oct 2024 23:26:47 +0900 Subject: [PATCH] =?UTF-8?q?refactor(review-write):=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=ED=8E=98=EC=9D=B4=EC=A7=80=20url=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(=EC=BF=BC=EB=A6=AC=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=EB=A1=9C=20id,=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC,=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=A0=84=EB=8B=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/my-challenge-record/index.tsx | 19 ++++++++++++++++--- src/pages/review-write/index.tsx | 18 +++++++----------- src/routes/index.tsx | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/pages/my-challenge-record/index.tsx b/src/pages/my-challenge-record/index.tsx index 661cd83..3061dae 100644 --- a/src/pages/my-challenge-record/index.tsx +++ b/src/pages/my-challenge-record/index.tsx @@ -43,8 +43,16 @@ const MyChallengeRecord = () => { return () => window.removeEventListener('scroll', handleScroll); }, [loadMoreChallenges]); - const handleNavigate = (id: number) => { - navigate(`/challenge/${id}/review`); + const handleChallengeClick = ( + challengeId: number, + title: string, + category?: string + ) => { + if (category) { + navigate( + `/challenge/write?id=${challengeId}&category=${category}&title=${title}` + ); + } else navigate(`/challenge/write?id=${challengeId}&title=${title}`); }; return ( @@ -67,7 +75,12 @@ const MyChallengeRecord = () => { challengeTitle={challenge.challengeTitle} userNickname={challenge.user.nickname} profileImageUrl={challenge.user.profileImageUrl} - onClick={() => handleNavigate(challenge.challengeId)} + onClick={() => + handleChallengeClick( + challenge.challengeId, + challenge.challengeTitle + ) + } /> )) ) : ( diff --git a/src/pages/review-write/index.tsx b/src/pages/review-write/index.tsx index 32c4628..401d663 100644 --- a/src/pages/review-write/index.tsx +++ b/src/pages/review-write/index.tsx @@ -1,5 +1,4 @@ import { useEffect, useState } from 'react'; -import { useParams } from 'react-router-dom'; import { postReview } from '@/apis/review/review.api'; import ChallengeTitle from '@/components/common/challenge-title'; @@ -7,7 +6,6 @@ import CTA, { CTAContainer } from '@/components/common/cta'; import Textarea from '@/components/common/form/textarea'; import { StarRating } from '@/components/common/star-rating'; import TopBar, { HEADER_HEIGHT } from '@/components/features/layout/top-bar'; -import { useChallengeStore } from '@/store/useChallengeStore'; import { formatRating, formatDifficulty, @@ -19,12 +17,11 @@ import styled from '@emotion/styled'; const MIN_CONTENT_LENGTH = 20; const ReviewWrite = () => { - const { id } = useParams(); - const challengeId = Number(id); - // const challengeGrouptitle = sessionStorage.getItem('challengeGroupTitle'); - const categoryLabel = sessionStorage.getItem('categoryLabel'); - const { challengeTitle } = useChallengeStore(); - // const challengeGroupTitle = sessionStorage.getItem('challengeGroupTitle'); + // 쿼리 파라미터 추출 + const searchParams = new URLSearchParams(location.search); + const challengeId = Number(searchParams.get('id')); + const category = searchParams.get('category') || ''; + const title = searchParams.get('title') || ''; const [rating, setRating] = useState(0); const difficultyList = [1, 2, 3]; @@ -103,9 +100,8 @@ const ReviewWrite = () => { <> - {categoryLabel && challengeTitle && ( - - )} + + diff --git a/src/routes/index.tsx b/src/routes/index.tsx index a0d799a..37d2c62 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -119,7 +119,7 @@ const router = createBrowserRouter([ ), }, { - path: `:id/${RouterPath.write}`, + path: `${RouterPath.write}`, element: (