Skip to content

Commit f855421

Browse files
committed
Merge branch 'dev' of https://github.com/CommitField/commitfield-front into check81
2 parents 777a0a4 + 7ae6502 commit f855421

File tree

6 files changed

+44
-23
lines changed

6 files changed

+44
-23
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ button {
6060
background-color: #1a1a1a;
6161
cursor: pointer;
6262
transition: border-color 0.25s;
63+
color: #fefefe;
6364
}
6465
button:hover {
6566
border-color: #646cff;

src/pages/Home.jsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,15 @@ useEffect(() => {
168168
newClient.subscribe(`/topic/notifications/${userInfo.username}`, (message) => {
169169
const notifications = JSON.parse(message.body);
170170

171-
// 배열인 경우 처리
172-
if (Array.isArray(notifications)) {
173-
// 각 알림을 상태에 추가
174-
notifications.forEach(notification => {
175-
setNotifications(prev => [{
176-
id: notification.id,
177-
message: notification.message,
178-
createdAt: notification.formattedCreatedAt,
179-
read: false
180-
}, ...prev]);
181-
});
182-
} else {
183-
// 단일 알림인 경우
171+
// 각 알림을 상태에 추가
172+
notifications.forEach(notification => {
184173
setNotifications(prev => [{
185-
id: notifications.id,
186-
message: notifications.message,
187-
createdAt: notifications.formattedCreatedAt,
174+
id: notification.id,
175+
message: notification.message,
176+
formattedCreatedAt: notification.formattedCreatedAt,
188177
read: false
189178
}, ...prev]);
190-
}
179+
});
191180

192181
// 새 알림 표시
193182
setHasNewNotification(true);

src/pages/Pets.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,12 @@ body {
8181
.home-button:hover {
8282
background-color: #f0f0f0;
8383
}
84+
85+
.heart {
86+
position: absolute;
87+
font-size: 24px;
88+
color: red;
89+
left: 50%;
90+
transform: translateX(-50%);
91+
pointer-events: none;
92+
}

src/pages/Pets.jsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useEffect, useState } from "react";
22
import { motion } from "framer-motion";
3-
import { useNavigate } from "react-router-dom"; // React Router 사용
3+
import { useNavigate } from "react-router-dom";
44
import "./Pets.css";
55

66
const Pets = () => {
77
const [pets, setPets] = useState([]);
8-
const navigate = useNavigate(); // 홈으로 돌아가기 함수
8+
const navigate = useNavigate();
99

1010
useEffect(() => {
1111
fetch("/api/pets/getall")
@@ -21,7 +21,6 @@ const Pets = () => {
2121
))}
2222
</div>
2323

24-
{/* 홈으로 돌아가기 버튼 추가 */}
2524
<div className="home-button-container">
2625
<button className="home-button" onClick={() => navigate("/home")}>
2726
홈으로 돌아가기
@@ -33,11 +32,12 @@ const Pets = () => {
3332

3433
const Pet = ({ src }) => {
3534
const getRandomPosition = () => ({
36-
x: Math.random() * 600 + 100, // 100 ~ 700 사이 랜덤 X 좌표
37-
y: Math.random() * 400 + 100, // 100 ~ 500 사이 랜덤 Y 좌표
35+
x: Math.random() * 600 + 100,
36+
y: Math.random() * 400 + 100,
3837
});
3938

4039
const [position, setPosition] = useState(getRandomPosition());
40+
const [showHeart, setShowHeart] = useState(false);
4141

4242
useEffect(() => {
4343
const movePet = () => {
@@ -48,14 +48,32 @@ const Pet = ({ src }) => {
4848
return () => clearInterval(interval);
4949
}, []);
5050

51+
const handlePetClick = () => {
52+
setShowHeart(true);
53+
setTimeout(() => setShowHeart(false), 1000); // 1초 후 사라지게 설정
54+
};
55+
5156
return (
5257
<motion.div
5358
className="pet-wrapper"
5459
initial={{ x: position.x, y: position.y }}
5560
animate={{ x: position.x, y: position.y }}
5661
transition={{ duration: 1.5, ease: "easeInOut" }}
62+
onClick={handlePetClick}
5763
>
5864
<img className="pet-egg" src={src} alt="Pet" />
65+
66+
{/* ❤️ 하트 애니메이션 */}
67+
{showHeart && (
68+
<motion.div
69+
className="heart"
70+
initial={{ opacity: 1, y: -60 }}
71+
animate={{ opacity: 0, y: -120 }}
72+
transition={{ duration: 1, ease: "easeOut" }}
73+
>
74+
❤️
75+
</motion.div>
76+
)}
5977
</motion.div>
6078
);
6179
};

src/pages/Profile.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ const handleGetNewPet = async () => {
125125
});
126126
};
127127

128+
useEffect(() => {
129+
refreshProfileData();
130+
}, [userInfo.tier, userInfo.petGrow]); // tier 또는 petGrow 값이 변경될 때 실행
131+
128132
useEffect(() => {
129133
// userInfo.username이 없으면 WebSocket 연결 안 함
130134
if (!userInfo.username) {
@@ -161,6 +165,7 @@ const handleGetNewPet = async () => {
161165
console.error("WebSocket error:", error);
162166
});
163167

168+
164169
// WebSocket 클라이언트 저장
165170
setClient(newClient);
166171

0 commit comments

Comments
 (0)