1
1
import React from "react" ;
2
2
import { List } from "immutable" ;
3
- import { connect , PromiseState } from "react-refetch" ;
4
3
import { Redirect } from "react-router-dom" ;
5
4
import { Alert , Spinner } from "reactstrap" ;
6
5
import { useVirtualContest } from "../../../api/InternalAPIClient" ;
@@ -23,18 +22,24 @@ interface Request {
23
22
penalty_second : number ;
24
23
}
25
24
26
- interface OuterProps {
25
+ interface Props {
27
26
contestId : string ;
28
27
}
29
28
30
- interface InnerProps extends OuterProps {
31
- updateResponse : PromiseState < unknown | null > ;
32
- updateContest : ( request : Request , problems : VirtualContestItem [ ] ) => void ;
33
- }
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 === 200 ;
37
+ } ;
34
38
35
- const InnerContestUpdatePage = ( props : InnerProps ) => {
36
- const { contestId, updateResponse } = props ;
39
+ export const ContestUpdatePage = ( props : Props ) => {
40
+ const { contestId } = props ;
37
41
const contestResponse = useVirtualContest ( contestId ) ;
42
+ const [ updateResponse , setUpdateResponse ] = React . useState < boolean > ( false ) ;
38
43
if ( ! contestResponse . data && ! contestResponse . error ) {
39
44
return < Spinner style = { { width : "3rem" , height : "3rem" } } /> ;
40
45
} else if ( contestResponse . error || ! contestResponse . data ) {
@@ -44,7 +49,7 @@ const InnerContestUpdatePage = (props: InnerProps) => {
44
49
const contestInfo = contestResponse . data . info ;
45
50
const contestProblems = contestResponse . data . problems ;
46
51
47
- if ( updateResponse . fulfilled && updateResponse . value !== null ) {
52
+ if ( updateResponse ) {
48
53
return < Redirect to = { `/contest/show/${ contestId } ` } /> ;
49
54
}
50
55
@@ -76,7 +81,7 @@ const InnerContestUpdatePage = (props: InnerProps) => {
76
81
initialPublicState = { contestInfo . is_public }
77
82
initialPenaltySecond = { contestInfo . penalty_second }
78
83
buttonTitle = "Update"
79
- buttonPush = { ( {
84
+ buttonPush = { async ( {
80
85
title,
81
86
memo,
82
87
startSecond,
@@ -85,8 +90,8 @@ const InnerContestUpdatePage = (props: InnerProps) => {
85
90
mode,
86
91
publicState,
87
92
penaltySecond,
88
- } ) : void => {
89
- props . updateContest (
93
+ } ) => {
94
+ const status = await createAndUpdateContest (
90
95
{
91
96
id : contestId ,
92
97
title,
@@ -99,22 +104,8 @@ const InnerContestUpdatePage = (props: InnerProps) => {
99
104
} ,
100
105
ps . toArray ( )
101
106
) ;
107
+ setUpdateResponse ( status ) ;
102
108
} }
103
109
/>
104
110
) ;
105
111
} ;
106
-
107
- export const ContestUpdatePage = connect < OuterProps , InnerProps > ( ( props ) => ( {
108
- updateContest : ( request : Request , problems : VirtualContestItem [ ] ) => ( {
109
- updateResponse : {
110
- comparison : null ,
111
- value : ( ) =>
112
- updateVirtualContestInfo ( request ) . then ( ( ) =>
113
- updateVirtualContestItems ( props . contestId , problems )
114
- ) ,
115
- } ,
116
- } ) ,
117
- updateResponse : {
118
- value : null ,
119
- } ,
120
- } ) ) ( InnerContestUpdatePage ) ;
0 commit comments