@@ -78,9 +78,10 @@ function RankingPage() {
78
78
79
79
const categoryChange = [ '공격 횟수' , '승리 횟수' ] ;
80
80
const [ categoryButtonState , setCategoryButtonState ] = useState ( 1 ) ;
81
- const [ modeButtonState , setModeButtonState ] = useState ( 1 ) ;
81
+ const [ modeButtonState , setModeButtonState ] = useState ( 0 ) ;
82
82
const [ players , setPlayers ] = useState ( [ ] ) ;
83
83
const inputRef = useRef < HTMLInputElement > ( null ) ;
84
+ const searchRef = useRef < any > ( null ) ;
84
85
85
86
const categoryButton : MouseEventHandler < HTMLButtonElement > = (
86
87
e : MouseEvent < HTMLButtonElement >
@@ -89,11 +90,6 @@ function RankingPage() {
89
90
setCategoryButtonState ( value ) ;
90
91
} ;
91
92
92
- const modeButton : MouseEventHandler < HTMLButtonElement > = ( e : MouseEvent < HTMLButtonElement > ) => {
93
- const value = ( e . target as Element ) . id === 'normal' ? 0 : 1 ;
94
- setModeButtonState ( value ) ;
95
- } ;
96
-
97
93
const searchButton : MouseEventHandler < HTMLButtonElement > = async (
98
94
e : MouseEvent < HTMLButtonElement >
99
95
) => {
@@ -103,6 +99,13 @@ function RankingPage() {
103
99
setPlayers ( res . data ) ;
104
100
} ;
105
101
102
+ const handleKeyPress = ( e : any ) => {
103
+ if ( e . key === 'Enter' ) {
104
+ const searchButton : any = searchRef . current ;
105
+ searchButton . click ( ) ;
106
+ }
107
+ } ;
108
+
106
109
useEffect ( ( ) => {
107
110
( async function effect ( ) {
108
111
syncKeyWithServer ( rankApiTemplate , categoryButtonState , modeButtonState ) ;
@@ -112,22 +115,22 @@ function RankingPage() {
112
115
} , [ categoryButtonState , modeButtonState ] ) ;
113
116
114
117
useEffect ( ( ) => {
115
- if ( ! isReady ) return ;
118
+ if ( ! isReady ) return ;
116
119
117
120
const popstateEvent = ( e : any ) => {
118
121
const url = e . target . location . pathname ;
119
122
120
- if ( url . includes ( '/game/' ) ) {
123
+ if ( url . includes ( '/game/' ) ) {
121
124
const gameID = url . split ( '/game/' ) [ 1 ] ;
122
125
socketClient . current . emit ( 'check valid room' , { roomID : gameID , id : socketClient . id } ) ;
123
126
}
124
- }
127
+ } ;
125
128
126
129
window . addEventListener ( 'popstate' , popstateEvent ) ;
127
130
128
131
return ( ) => {
129
132
window . removeEventListener ( 'popstate' , popstateEvent ) ;
130
- }
133
+ } ;
131
134
} , [ isReady ] ) ;
132
135
133
136
return (
@@ -156,17 +159,9 @@ function RankingPage() {
156
159
</ div >
157
160
< div className = "rank__input__box__row" >
158
161
모드 :
159
- < button
160
- id = "1 vs 1"
161
- className = { `rank__input__box__button ${ modeButtonState && 'selected' } ` }
162
- onClick = { modeButton }
163
- >
164
- 1 vs 1
165
- </ button >
166
162
< button
167
163
id = "normal"
168
164
className = { `rank__input__box__button ${ ! modeButtonState && 'selected' } ` }
169
- onClick = { modeButton }
170
165
>
171
166
일반전
172
167
</ button >
@@ -176,9 +171,11 @@ function RankingPage() {
176
171
className = "rank__input__box__nickname"
177
172
placeholder = "플레이어 닉네임을 입력해주세요."
178
173
ref = { inputRef }
174
+ onKeyPress = { handleKeyPress }
179
175
> </ input >
180
176
< button
181
177
className = "rank__input__box__button rank__nickname__search"
178
+ ref = { searchRef }
182
179
onClick = { searchButton }
183
180
>
184
181
검색
0 commit comments