-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGamePage.tsx
More file actions
175 lines (162 loc) · 4.48 KB
/
GamePage.tsx
File metadata and controls
175 lines (162 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { useState } from 'react';
import { motion } from 'framer-motion';
import { useClickGame, useGameRanking } from '@/hooks/Queries/useGame';
import ClickButton from './components/ClickButton/ClickButton';
import ClubNameInput from './components/ClubNameInput/ClubNameInput';
import DotTextEffect from './components/DotTextEffect/DotTextEffect';
import RankingBoard from './components/RankingBoard/RankingBoard';
import * as S from './GamePage.styles';
const STORAGE_KEY = 'game_club_name';
const BLOBS = [
{
size: 320,
top: '-80px',
left: '-100px',
color: 'rgba(255, 84, 20, 0.12)',
dy: 30,
duration: 7,
},
{
size: 260,
top: '20%',
left: '75%',
color: 'rgba(255, 157, 124, 0.15)',
dy: -40,
duration: 9,
},
{
size: 200,
top: '55%',
left: '-60px',
color: 'rgba(255, 212, 50, 0.12)',
dy: 25,
duration: 11,
},
{
size: 180,
top: '70%',
left: '80%',
color: 'rgba(95, 216, 192, 0.13)',
dy: -30,
duration: 8,
},
{
size: 140,
top: '40%',
left: '45%',
color: 'rgba(112, 148, 255, 0.1)',
dy: 20,
duration: 13,
},
];
const GamePage = () => {
const [clubName, setClubName] = useState<string>(
() => sessionStorage.getItem(STORAGE_KEY) ?? '',
);
const [myClickCount, setMyClickCount] = useState(0);
const { data: rankingData } = useGameRanking();
const { mutate: clickGame } = useClickGame();
const top1Club = rankingData?.clubs[0];
const handleStart = (name: string) => {
sessionStorage.setItem(STORAGE_KEY, name);
setClubName(name);
};
const handleClick = () => {
clickGame(clubName, {
onSuccess: (data) => setMyClickCount(data.clickCount),
});
};
return (
<S.PageContainer>
{BLOBS.map((blob, i) => (
<motion.div
key={i}
style={{ position: 'absolute', zIndex: 0 }}
animate={{ y: [0, blob.dy, 0] }}
transition={{
duration: blob.duration,
repeat: Infinity,
ease: 'easeInOut',
}}
>
<S.Blob
$size={blob.size}
$top={blob.top}
$left={blob.left}
$color={blob.color}
/>
</motion.div>
))}
<S.Content>
{/* 상단: 타이틀(좌) + 실시간 순위(우) */}
<S.TopRow>
<motion.div
initial={{ opacity: 0, y: -16 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
<S.PageTitle>동아리 클릭 배틀</S.PageTitle>
<S.PageDescription>
우리 동아리를 응원해주세요! 클릭할수록 순위가 올라가요.
</S.PageDescription>
</motion.div>
<motion.div
initial={{ opacity: 0, x: 24 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.5, delay: 0.3 }}
>
<RankingBoard
ranking={rankingData?.clubs ?? []}
resetAt={rankingData?.resetAt ?? new Date().toISOString()}
myClubName={clubName}
/>
</motion.div>
</S.TopRow>
{/* 중앙: 도트 글자 */}
{top1Club && (
<motion.div
initial={{ opacity: 0, scale: 0.92 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ duration: 0.4, delay: 0.15 }}
style={{ display: 'flex', justifyContent: 'center', width: '100%' }}
>
<DotTextEffect
text={top1Club.clubName}
fontSize={100}
spacing={4}
dotR={1.8}
hoverRadius={18}
charColors={[
'#FF5414',
'#FFB300',
'#5FD8C0',
'#7094FF',
'#D4537E',
'#EF9F27',
'#FF9D7C',
]}
/>
</motion.div>
)}
{/* 하단: 클릭 버튼 */}
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.4, delay: 0.25 }}
style={{ marginTop: '40px' }}
>
{!clubName ? (
<ClubNameInput onStart={handleStart} />
) : (
<ClickButton
clubName={clubName}
clickCount={myClickCount}
onClickGame={handleClick}
/>
)}
</motion.div>
</S.Content>
</S.PageContainer>
);
};
export default GamePage;