Skip to content

Commit aa17c10

Browse files
committed
add system now remember which your choose
1 parent f77ab7d commit aa17c10

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@emotion/react": "11.9.0",
13+
"@emotion/styled": "11.8.1",
14+
"@mui/material": "5.8.1",
1215
"axios": "0.27.2",
1316
"cookie": "0.5.0",
1417
"event-source-polyfill": "1.0.26",
@@ -20,6 +23,7 @@
2023
"nprogress": "0.2.0",
2124
"react": "18.1.0",
2225
"react-dom": "18.1.0",
26+
"react-draggable": "4.4.5",
2327
"react-full-screen": "1.1.0",
2428
"react-markdown-editor-lite": "1.3.2",
2529
"react-toastify": "9.0.1"

pages/index.js

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import styles from '../css/index.module.css';
77
import {infoMatch, joinMatch, quitMatch} from "../apis/match";
88
import {EventSourcePolyfill} from "event-source-polyfill";
99
import {useRouter} from "next/router";
10+
import {Box, CircularProgress, FormControl, InputLabel, MenuItem, Select} from "@mui/material";
1011

1112
export default function Index() {
1213
const eventSource = useRef();
@@ -19,6 +20,7 @@ export default function Index() {
1920
useEffect(() => {
2021
infoMatch().then((response) => {
2122
if (response.code === "0") {
23+
setGamerSize(parseInt(response.data.choose));
2224
setSize(response.data.size);
2325
setMatching(response.data.join);
2426
}
@@ -46,12 +48,10 @@ export default function Index() {
4648
}
4749

4850
eventSource.current.addEventListener("match_info", (event) => {
49-
console.log("match_info ", event.data)
5051
setSize(event.data);
5152
});
5253

5354
eventSource.current.addEventListener("match_found", (event) => {
54-
console.log("match_found ", event.data)
5555
router.push("/room/" + event.data).then(r => r);
5656
});
5757

@@ -66,7 +66,7 @@ export default function Index() {
6666

6767
if (matching) {
6868
button = <CallApiButton
69-
buttonText={'取消匹配,' + size + '人正在匹配中'}
69+
buttonText={'取消匹配'}
7070
loadingText={'正在取消'}
7171
api={quitMatch}
7272
onSuccess={() => {
@@ -75,7 +75,7 @@ export default function Index() {
7575
/>
7676
} else {
7777
button = <CallApiButton
78-
buttonText={'开始匹配,' + size + '人正在匹配中'}
78+
buttonText={'开始匹配'}
7979
loadingText={'正在匹配'}
8080
api={joinMatch}
8181
params={{
@@ -92,20 +92,45 @@ export default function Index() {
9292
<>
9393
<GlobalHeader/>
9494
<div className={styles.container}>
95-
<div>
96-
选择人数&nbsp;
97-
<select onChange={(event) => setGamerSize(event.target.value)}>
98-
<option>2</option>
99-
<option>3</option>
100-
<option>4</option>
101-
<option>5</option>
102-
<option>6</option>
103-
<option>7</option>
104-
<option>8</option>
105-
<option>9</option>
106-
</select>
107-
</div>
108-
{button}
95+
<FormControl sx={{m: 1, minWidth: 80}}>
96+
<InputLabel id="demo-simple-select-autowidth-label">人数</InputLabel>
97+
<Select
98+
labelId="demo-simple-select-autowidth-label"
99+
id="demo-simple-select-autowidth"
100+
value={gamerSize}
101+
onChange={(event) => {
102+
setGamerSize(event.target.value);
103+
}}
104+
autoWidth
105+
label="Age"
106+
disabled={matching}
107+
>
108+
<MenuItem value={2}>2人</MenuItem>
109+
<MenuItem value={3}>3人</MenuItem>
110+
<MenuItem value={4}>4人</MenuItem>
111+
<MenuItem value={5}>5人</MenuItem>
112+
<MenuItem value={6}>6人</MenuItem>
113+
<MenuItem value={7}>7人</MenuItem>
114+
<MenuItem value={8}>8人</MenuItem>
115+
<MenuItem value={9}>9人</MenuItem>
116+
</Select>
117+
</FormControl>
118+
<Box sx={{display: 'flex'}}>
119+
{button}
120+
</Box>
121+
{
122+
matching ?
123+
<>
124+
<Box sx={{display: 'flex'}}>
125+
<CircularProgress/>
126+
</Box>
127+
<Box sx={{display: 'flex'}}>
128+
<p>{'当前队列 ' + size + ' 人'}</p>
129+
</Box>
130+
</>
131+
:
132+
<></>
133+
}
109134
</div>
110135
<Footer/>
111136
</>

0 commit comments

Comments
 (0)