Skip to content

Commit 979e59f

Browse files
authored
Merge pull request #197 from boostcampwm-2021/feature/196
[랭킹] 1vs1 지우기, css 작업, 검색 기능 개선
2 parents b43c177 + 5ac8ff6 commit 979e59f

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

front-end/src/pages/RankingPage/index.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ function RankingPage() {
7878

7979
const categoryChange = ['공격 횟수', '승리 횟수'];
8080
const [categoryButtonState, setCategoryButtonState] = useState(1);
81-
const [modeButtonState, setModeButtonState] = useState(1);
81+
const [modeButtonState, setModeButtonState] = useState(0);
8282
const [players, setPlayers] = useState([]);
8383
const inputRef = useRef<HTMLInputElement>(null);
84+
const searchRef = useRef<any>(null);
8485

8586
const categoryButton: MouseEventHandler<HTMLButtonElement> = (
8687
e: MouseEvent<HTMLButtonElement>
@@ -89,11 +90,6 @@ function RankingPage() {
8990
setCategoryButtonState(value);
9091
};
9192

92-
const modeButton: MouseEventHandler<HTMLButtonElement> = (e: MouseEvent<HTMLButtonElement>) => {
93-
const value = (e.target as Element).id === 'normal' ? 0 : 1;
94-
setModeButtonState(value);
95-
};
96-
9793
const searchButton: MouseEventHandler<HTMLButtonElement> = async (
9894
e: MouseEvent<HTMLButtonElement>
9995
) => {
@@ -103,6 +99,13 @@ function RankingPage() {
10399
setPlayers(res.data);
104100
};
105101

102+
const handleKeyPress = (e: any) => {
103+
if (e.key === 'Enter') {
104+
const searchButton: any = searchRef.current;
105+
searchButton.click();
106+
}
107+
};
108+
106109
useEffect(() => {
107110
(async function effect() {
108111
syncKeyWithServer(rankApiTemplate, categoryButtonState, modeButtonState);
@@ -112,22 +115,22 @@ function RankingPage() {
112115
}, [categoryButtonState, modeButtonState]);
113116

114117
useEffect(() => {
115-
if(!isReady) return;
118+
if (!isReady) return;
116119

117120
const popstateEvent = (e: any) => {
118121
const url = e.target.location.pathname;
119122

120-
if(url.includes('/game/')) {
123+
if (url.includes('/game/')) {
121124
const gameID = url.split('/game/')[1];
122125
socketClient.current.emit('check valid room', { roomID: gameID, id: socketClient.id });
123126
}
124-
}
127+
};
125128

126129
window.addEventListener('popstate', popstateEvent);
127130

128131
return () => {
129132
window.removeEventListener('popstate', popstateEvent);
130-
}
133+
};
131134
}, [isReady]);
132135

133136
return (
@@ -156,17 +159,9 @@ function RankingPage() {
156159
</div>
157160
<div className="rank__input__box__row">
158161
모드 :
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>
166162
<button
167163
id="normal"
168164
className={`rank__input__box__button ${!modeButtonState && 'selected'}`}
169-
onClick={modeButton}
170165
>
171166
일반전
172167
</button>
@@ -176,9 +171,11 @@ function RankingPage() {
176171
className="rank__input__box__nickname"
177172
placeholder="플레이어 닉네임을 입력해주세요."
178173
ref={inputRef}
174+
onKeyPress={handleKeyPress}
179175
></input>
180176
<button
181177
className="rank__input__box__button rank__nickname__search"
178+
ref={searchRef}
182179
onClick={searchButton}
183180
>
184181
검색

front-end/src/pages/RankingPage/style.scss

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
display: flex;
1818
width: 100%;
1919
height: 30vh;
20-
margin-left: 100px;
20+
padding-right: 140px;
2121
justify-content: center;
2222
align-items: center;
2323
}
2424
.rank__player__box {
2525
display: flex;
2626
background: #364171;
2727
height: 140px;
28-
width: 402px;
28+
width: 100%;
29+
margin: 200px 60px 200px 200px;
2930
box-shadow: 0px 7px #272d4e;
3031
.rank__player__image {
3132
display: flex;
@@ -49,9 +50,9 @@
4950
.rank__input__box {
5051
display: flex;
5152
flex-direction: column;
52-
margin-left: 70px;
53-
width: 500px;
54-
height: 116px;
53+
width: 100%;
54+
height: 140px;
55+
margin-left: 50px;
5556
}
5657
.rank__input__box__row {
5758
display: flex;
@@ -90,16 +91,17 @@
9091

9192
.rank__body__down {
9293
display: flex;
93-
margin-left: 230px;
9494
width: 100%;
95-
height: 18vh;
95+
min-height: 200px;
9696
}
9797

9898
.rank__display {
9999
display: flex;
100100
flex-direction: column;
101-
width: 750px;
102-
height: 100%;
101+
width: 100%;
102+
height: 17vh;
103+
padding-left: 230px;
104+
padding-right: 230px;
103105
}
104106
.rank__display__scroll__root {
105107
overflow: auto;

0 commit comments

Comments
 (0)