Skip to content

Commit 22e7ca1

Browse files
authored
Merge pull request #1074 from atsuya02/ContestUpdatePage_branch
ContestUpdatePageのreact-refetch を置き換える
2 parents 0052e7e + ae57b44 commit 22e7ca1

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

atcoder-problems-frontend/src/pages/Internal/VirtualContest/ApiClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const updateVirtualContestItems = (
6666
order: i,
6767
})),
6868
}),
69-
}).then(() => ({}));
69+
}).then((response) => response);
7070

7171
export const joinContest = (contestId: string) =>
7272
fetch(CONTEST_JOIN, {

atcoder-problems-frontend/src/pages/Internal/VirtualContest/ContestUpdatePage.tsx

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from "react";
22
import { List } from "immutable";
3-
import { connect, PromiseState } from "react-refetch";
43
import { Redirect } from "react-router-dom";
54
import { Alert, Spinner } from "reactstrap";
65
import { useVirtualContest } from "../../../api/InternalAPIClient";
@@ -23,18 +22,24 @@ interface Request {
2322
penalty_second: number;
2423
}
2524

26-
interface OuterProps {
25+
interface Props {
2726
contestId: string;
2827
}
2928

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+
};
3438

35-
const InnerContestUpdatePage = (props: InnerProps) => {
36-
const { contestId, updateResponse } = props;
39+
export const ContestUpdatePage = (props: Props) => {
40+
const { contestId } = props;
3741
const contestResponse = useVirtualContest(contestId);
42+
const [updateResponse, setUpdateResponse] = React.useState<boolean>(false);
3843
if (!contestResponse.data && !contestResponse.error) {
3944
return <Spinner style={{ width: "3rem", height: "3rem" }} />;
4045
} else if (contestResponse.error || !contestResponse.data) {
@@ -44,7 +49,7 @@ const InnerContestUpdatePage = (props: InnerProps) => {
4449
const contestInfo = contestResponse.data.info;
4550
const contestProblems = contestResponse.data.problems;
4651

47-
if (updateResponse.fulfilled && updateResponse.value !== null) {
52+
if (updateResponse) {
4853
return <Redirect to={`/contest/show/${contestId}`} />;
4954
}
5055

@@ -76,7 +81,7 @@ const InnerContestUpdatePage = (props: InnerProps) => {
7681
initialPublicState={contestInfo.is_public}
7782
initialPenaltySecond={contestInfo.penalty_second}
7883
buttonTitle="Update"
79-
buttonPush={({
84+
buttonPush={async ({
8085
title,
8186
memo,
8287
startSecond,
@@ -85,8 +90,8 @@ const InnerContestUpdatePage = (props: InnerProps) => {
8590
mode,
8691
publicState,
8792
penaltySecond,
88-
}): void => {
89-
props.updateContest(
93+
}) => {
94+
const status = await createAndUpdateContest(
9095
{
9196
id: contestId,
9297
title,
@@ -99,22 +104,8 @@ const InnerContestUpdatePage = (props: InnerProps) => {
99104
},
100105
ps.toArray()
101106
);
107+
setUpdateResponse(status);
102108
}}
103109
/>
104110
);
105111
};
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

Comments
 (0)