@@ -7,6 +7,7 @@ import styles from '../css/index.module.css';
7
7
import { infoMatch , joinMatch , quitMatch } from "../apis/match" ;
8
8
import { EventSourcePolyfill } from "event-source-polyfill" ;
9
9
import { useRouter } from "next/router" ;
10
+ import { Box , CircularProgress , FormControl , InputLabel , MenuItem , Select } from "@mui/material" ;
10
11
11
12
export default function Index ( ) {
12
13
const eventSource = useRef ( ) ;
@@ -19,6 +20,7 @@ export default function Index() {
19
20
useEffect ( ( ) => {
20
21
infoMatch ( ) . then ( ( response ) => {
21
22
if ( response . code === "0" ) {
23
+ setGamerSize ( parseInt ( response . data . choose ) ) ;
22
24
setSize ( response . data . size ) ;
23
25
setMatching ( response . data . join ) ;
24
26
}
@@ -46,12 +48,10 @@ export default function Index() {
46
48
}
47
49
48
50
eventSource . current . addEventListener ( "match_info" , ( event ) => {
49
- console . log ( "match_info " , event . data )
50
51
setSize ( event . data ) ;
51
52
} ) ;
52
53
53
54
eventSource . current . addEventListener ( "match_found" , ( event ) => {
54
- console . log ( "match_found " , event . data )
55
55
router . push ( "/room/" + event . data ) . then ( r => r ) ;
56
56
} ) ;
57
57
@@ -66,7 +66,7 @@ export default function Index() {
66
66
67
67
if ( matching ) {
68
68
button = < CallApiButton
69
- buttonText = { '取消匹配,' + size + '人正在匹配中 '}
69
+ buttonText = { '取消匹配' }
70
70
loadingText = { '正在取消' }
71
71
api = { quitMatch }
72
72
onSuccess = { ( ) => {
@@ -75,7 +75,7 @@ export default function Index() {
75
75
/>
76
76
} else {
77
77
button = < CallApiButton
78
- buttonText = { '开始匹配,' + size + '人正在匹配中 '}
78
+ buttonText = { '开始匹配' }
79
79
loadingText = { '正在匹配' }
80
80
api = { joinMatch }
81
81
params = { {
@@ -92,20 +92,45 @@ export default function Index() {
92
92
< >
93
93
< GlobalHeader />
94
94
< div className = { styles . container } >
95
- < div >
96
- 选择人数
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
+ }
109
134
</ div >
110
135
< Footer />
111
136
</ >
0 commit comments