@@ -7,10 +7,8 @@ import { getAvatarByID } from '../Avatar/Avatar';
7
7
import {
8
8
LeaderboardApi ,
9
9
MatchApi ,
10
- CodeApi ,
11
- MapApi ,
12
- CreateMatchRequest ,
13
10
LeaderboardEntry ,
11
+ MatchMode ,
14
12
} from '@codecharacter-2022/client' ;
15
13
import { apiConfig , ApiError } from '../../api/ApiConfig' ;
16
14
import Loader from '../Loader/Loader' ;
@@ -24,11 +22,11 @@ function PaginatedItems() {
24
22
const [ currentItems , setCurrentItems ] = useState < LeaderboardEntry [ ] > ( [ ] ) ;
25
23
const [ isLoaded , setIsLoaded ] = useState ( false ) ;
26
24
const [ show , setShow ] = useState ( false ) ;
27
- let currentOpponentId : string ;
25
+ const [ currentOpponentUsername , setCurrentOpponentUsername ] = useState ( '' ) ;
28
26
29
27
const handleClose = ( ) => setShow ( false ) ;
30
- const handleShow = ( opponentId : string ) => {
31
- currentOpponentId = opponentId ;
28
+ const handleShow = ( username : string ) => {
29
+ setCurrentOpponentUsername ( username ) ;
32
30
setShow ( true ) ;
33
31
} ;
34
32
@@ -42,7 +40,7 @@ function PaginatedItems() {
42
40
const endOffset = itemOffset + itemsPerPage ;
43
41
setCurrentItems ( items . slice ( itemOffset , endOffset ) ) ;
44
42
setPageCount ( Math . ceil ( items . length / itemsPerPage ) ) ;
45
- } , [ itemOffset , itemsPerPage ] ) ;
43
+ } , [ itemOffset , itemsPerPage , items ] ) ;
46
44
47
45
const handlePageClick = ( event : { selected : number } ) => {
48
46
const newOffset = ( event . selected * itemsPerPage ) % items . length ;
@@ -64,30 +62,17 @@ function PaginatedItems() {
64
62
} ;
65
63
66
64
async function handleMatchStart ( ) {
67
- enum MatchMode {
68
- Self = 'SELF' ,
69
- Manual = 'MANUAL' ,
70
- Auto = 'AUTO' ,
71
- }
72
- const codeAPI = new CodeApi ( apiConfig ) ;
73
- const mapAPI = new MapApi ( apiConfig ) ;
74
- const codeRevisionId = await codeAPI . getCodeRevisions ( ) . then ( response => {
75
- response [ response . length - 1 ] . parentRevision ;
76
- } ) ;
77
- const mapRevisionId = await mapAPI . getMapRevisions ( ) . then ( response => {
78
- response [ response . length - 1 ] . parentRevision ;
79
- } ) ;
80
- const matchRequest = {
81
- mode : MatchMode . Self ,
82
- opponentId : currentOpponentId ,
83
- codeRevisionId : codeRevisionId ,
84
- mapRevisionId : mapRevisionId ,
85
- } ;
86
-
87
65
const matchAPI = new MatchApi ( apiConfig ) ;
88
- matchAPI . createMatch ( matchRequest as CreateMatchRequest ) . catch ( error => {
89
- if ( error instanceof ApiError ) console . log ( error ) ;
90
- } ) ;
66
+ matchAPI
67
+ . createMatch ( {
68
+ mode : MatchMode . Manual ,
69
+ opponentUsername : currentOpponentUsername ,
70
+ codeRevisionId : undefined ,
71
+ mapRevisionId : undefined ,
72
+ } )
73
+ . catch ( error => {
74
+ if ( error instanceof ApiError ) console . log ( error ) ;
75
+ } ) ;
91
76
setShow ( false ) ;
92
77
}
93
78
return (
@@ -103,15 +88,16 @@ function PaginatedItems() {
103
88
< Modal . Title > Start a new match</ Modal . Title >
104
89
</ Modal . Header >
105
90
< Modal . Body className = { styles . editorSettingsBody } >
106
- Do you want to start a match ?
91
+ Do you want to start a match against { currentOpponentUsername }
92
+ ?
107
93
</ Modal . Body >
108
94
< Modal . Footer >
109
95
< Button variant = "secondary" onClick = { handleClose } >
110
96
Close
111
97
</ Button >
112
98
< Button
113
99
className = { styles . matchButton }
114
- onClick = { handleMatchStart }
100
+ onClick = { ( ) => handleMatchStart ( ) }
115
101
>
116
102
Start match
117
103
</ Button >
@@ -153,7 +139,9 @@ function PaginatedItems() {
153
139
src = { swordImage }
154
140
> </ img >
155
141
</ td >
156
- < td className = { styles . score } > { row . stats . rating } </ td >
142
+ < td className = { styles . score } >
143
+ { row . stats . rating . toFixed ( 3 ) }
144
+ </ td >
157
145
< td className = { styles . score } > { row . stats . wins } </ td >
158
146
< td className = { styles . score } > { row . stats . ties } </ td >
159
147
< td className = { styles . score } > { row . stats . losses } </ td >
0 commit comments