From c30fe630b31893f29b32249f014bb77e58f3a634 Mon Sep 17 00:00:00 2001 From: whale22 Date: Fri, 7 Mar 2025 11:16:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9B=B9=EC=86=8C=EC=BC=93=20=EC=9D=BC?= =?UTF-8?q?=EB=B6=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Profile.jsx | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/pages/Profile.jsx b/src/pages/Profile.jsx index 4896662..a4561f3 100644 --- a/src/pages/Profile.jsx +++ b/src/pages/Profile.jsx @@ -5,10 +5,10 @@ import Stomp from "stompjs"; const Profile = ({ userInfo }) => { const [seasonCommitCount, setSeasonCommitCount] = useState(userInfo.seasonCommitCount); const [petExp, setPetExp] = useState(userInfo.petExp); - const [username, setUsername] = useState(userInfo.username); - const [client, setClient] = useState(null); // WebSocket 클라이언트 상태 - const maxExp = userInfo.petGrow === 'EGG' ? 150 : userInfo.petGrow === 'HATCH' ? 300 : 300; const [commitCount, setCommitCount] = useState(0); + const [client, setClient] = useState(null); // WebSocket 클라이언트 상태 + + const maxExp = userInfo.petGrow === "EGG" ? 150 : userInfo.petGrow === "HATCH" ? 300 : 300; const tierEmojis = { SEED: "🌱", SPROUT: "🌿", @@ -20,9 +20,15 @@ const Profile = ({ userInfo }) => { // 경험치 바 계산 const progress = (petExp / maxExp) * 100; + // userInfo가 변경되면 값 업데이트 useEffect(() => { - // username이 없으면 대기 (WebSocket 연결 X) - if (!username) { + setSeasonCommitCount(userInfo.seasonCommitCount); + setPetExp(userInfo.petExp); + }, [userInfo]); + + useEffect(() => { + // userInfo.username이 없으면 WebSocket 연결 안 함 + if (!userInfo.username) { console.log("Username is not available yet, waiting..."); return; } @@ -45,6 +51,7 @@ const Profile = ({ userInfo }) => { newClient.subscribe(`/topic/commit/${userInfo.username}`, (message) => { const newCommitCount = JSON.parse(message.body); setCommitCount(newCommitCount); + // 시즌 커밋 수 업데이트 setSeasonCommitCount((prev) => prev + newCommitCount); @@ -65,18 +72,14 @@ const Profile = ({ userInfo }) => { }); } }; - }, [username]); // username이 변경될 때마다 WebSocket 연결 + }, [userInfo.username]); // username이 변경될 때마다 WebSocket 연결 return (
{/* 왼쪽: 펫 이미지 */}
- Pet + Pet
{/* 오른쪽: 사용자 정보 및 펫 정보 */} @@ -92,18 +95,20 @@ const Profile = ({ userInfo }) => {
🐾 펫 정보
-
+
-
{petExp} / {maxExp}
+
+ {petExp} / {maxExp} +
성장 단계: {userInfo.petGrow}