Skip to content

Commit 8fcdd1f

Browse files
committed
fix(game): ClubNameInput 드롭다운 재오픈 및 DotTextEffect 리사이즈 scale 버그 수정
- justSelectedRef로 선택 후 debounce useEffect 재트리거 차단 - ResizeObserver로 wrapper 리사이즈 시 canvas transform scale 동적 재계산
1 parent 0dd4243 commit 8fcdd1f

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

frontend/src/pages/GamePage/components/ClubNameInput/ClubNameInput.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useId, useState } from 'react';
1+
import { useEffect, useId, useRef, useState } from 'react';
22
import {
33
useClubSuggestions,
44
useValidateClubName,
@@ -18,8 +18,13 @@ const ClubNameInput = ({ onStart }: ClubNameInputProps) => {
1818
const [highlightedIndex, setHighlightedIndex] = useState(-1);
1919

2020
const listboxId = useId();
21+
const justSelectedRef = useRef(false);
2122

2223
useEffect(() => {
24+
if (justSelectedRef.current) {
25+
justSelectedRef.current = false;
26+
return;
27+
}
2328
const trimmed = value.trim();
2429
const timer = setTimeout(() => setDebouncedKeyword(trimmed), 300);
2530
return () => clearTimeout(timer);
@@ -39,6 +44,7 @@ const ClubNameInput = ({ onStart }: ClubNameInputProps) => {
3944
};
4045

4146
const handleSelect = (name: string) => {
47+
justSelectedRef.current = true;
4248
setValue(name);
4349
setDebouncedKeyword('');
4450
setHighlightedIndex(-1);

frontend/src/pages/GamePage/components/DotTextEffect/DotTextEffect.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const DotTextEffect = ({
140140
const mouseRef = useRef({ x: -999, y: -999 });
141141
const dotsRef = useRef<Dot[]>([]);
142142
const rafRef = useRef<number>(0);
143+
const canvasSizeRef = useRef({ W: 0, H: 0 });
143144

144145
const [isMobile, setIsMobile] = useState(() => mobileQuery.matches);
145146

@@ -173,6 +174,7 @@ const DotTextEffect = ({
173174
canvasH = H;
174175
canvas.width = W;
175176
canvas.height = H;
177+
canvasSizeRef.current = { W, H };
176178

177179
// 컨테이너 너비를 넘으면 CSS transform으로 축소 (항상 한 줄 유지)
178180
const wrapper = wrapperRef.current;
@@ -304,6 +306,24 @@ const DotTextEffect = ({
304306
charColors,
305307
]);
306308

309+
useEffect(() => {
310+
const wrapper = wrapperRef.current;
311+
const canvas = canvasRef.current;
312+
if (!wrapper || !canvas) return;
313+
314+
const observer = new ResizeObserver(() => {
315+
const { W, H } = canvasSizeRef.current;
316+
if (W === 0) return;
317+
const scale = Math.min(1, wrapper.clientWidth / W);
318+
canvas.style.transform = `scale(${scale})`;
319+
canvas.style.transformOrigin = 'center top';
320+
wrapper.style.height = `${H * scale}px`;
321+
});
322+
323+
observer.observe(wrapper);
324+
return () => observer.disconnect();
325+
}, []);
326+
307327
const handleMouseMove = (e: React.MouseEvent<HTMLCanvasElement>) => {
308328
const r = canvasRef.current!.getBoundingClientRect();
309329
mouseRef.current = { x: e.clientX - r.left, y: e.clientY - r.top };

0 commit comments

Comments
 (0)