@@ -2,10 +2,7 @@ import React from "react";
2
2
import { List } from "immutable" ;
3
3
import { Redirect } from "react-router-dom" ;
4
4
import { Alert , Spinner } from "reactstrap" ;
5
- import {
6
- useVirtualContest ,
7
- useContestUpdate ,
8
- } from "../../../api/InternalAPIClient" ;
5
+ import { useVirtualContest } from "../../../api/InternalAPIClient" ;
9
6
import * as DateUtil from "../../../utils/DateUtil" ;
10
7
import { VirtualContestItem } from "../types" ;
11
8
import {
@@ -29,30 +26,30 @@ interface OuterProps {
29
26
contestId : string ;
30
27
}
31
28
29
+ const createAndUpdateContest = async (
30
+ request : Request ,
31
+ problems : VirtualContestItem [ ]
32
+ ) => {
33
+ const response = await updateVirtualContestInfo ( request ) . then ( ( ) =>
34
+ updateVirtualContestItems ( request . id , problems )
35
+ ) ;
36
+ return response . status ;
37
+ } ;
38
+
32
39
export const ContestUpdatePage = ( props : OuterProps ) => {
33
40
const { contestId } = props ;
34
- const updateResponse = useContestUpdate ( ) ;
35
41
const contestResponse = useVirtualContest ( contestId ) ;
42
+ const [ updateResponse , setUpdateResponse ] = React . useState < number > ( ) ;
36
43
if ( ! contestResponse . data && ! contestResponse . error ) {
37
44
return < Spinner style = { { width : "3rem" , height : "3rem" } } /> ;
38
45
} else if ( contestResponse . error || ! contestResponse . data ) {
39
46
return < Alert color = "danger" > Failed to fetch contest info.</ Alert > ;
40
47
}
41
48
42
- const updateContest = ( request : Request , problems : VirtualContestItem [ ] ) => ( {
43
- updateResponse : {
44
- comparison : null ,
45
- value : ( ) =>
46
- updateVirtualContestInfo ( request ) . then ( ( ) =>
47
- updateVirtualContestItems ( props . contestId , problems )
48
- ) ,
49
- } ,
50
- } ) ;
51
-
52
49
const contestInfo = contestResponse . data . info ;
53
50
const contestProblems = contestResponse . data . problems ;
54
51
55
- if ( ! updateResponse . data && updateResponse . error ) {
52
+ if ( updateResponse === 200 ) {
56
53
return < Redirect to = { `/contest/show/${ contestId } ` } /> ;
57
54
}
58
55
@@ -84,7 +81,7 @@ export const ContestUpdatePage = (props: OuterProps) => {
84
81
initialPublicState = { contestInfo . is_public }
85
82
initialPenaltySecond = { contestInfo . penalty_second }
86
83
buttonTitle = "Update"
87
- buttonPush = { ( {
84
+ buttonPush = { async ( {
88
85
title,
89
86
memo,
90
87
startSecond,
@@ -93,8 +90,8 @@ export const ContestUpdatePage = (props: OuterProps) => {
93
90
mode,
94
91
publicState,
95
92
penaltySecond,
96
- } ) : void => {
97
- updateContest (
93
+ } ) => {
94
+ const status = await createAndUpdateContest (
98
95
{
99
96
id : contestId ,
100
97
title,
@@ -107,6 +104,7 @@ export const ContestUpdatePage = (props: OuterProps) => {
107
104
} ,
108
105
ps . toArray ( )
109
106
) ;
107
+ setUpdateResponse ( status ) ;
110
108
} }
111
109
/>
112
110
) ;
0 commit comments