Skip to content

Commit db46df4

Browse files
authored
Merge pull request #1063 from yb173/replace_old_api_recent_contest_list
RecentContestList の react-refetch を swr で置き換える
2 parents 75ff35d + af3e61f commit db46df4

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

atcoder-problems-frontend/src/api/InternalAPIClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,9 @@ export const useProgressResetList = () => {
4646
typeCastFetcher<ProgressResetList>(url)
4747
);
4848
};
49+
50+
export const useRecentContests = () => {
51+
return useSWRData(`${BASE_URL}/contest/recent`, (url) =>
52+
typeCastFetcher<VirtualContestInfo[]>(url)
53+
);
54+
};

atcoder-problems-frontend/src/pages/Internal/ApiUrl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export const CONTEST_UPDATE = `${BASE_URL}/contest/update`;
66
export const CONTEST_JOIN = `${BASE_URL}/contest/join`;
77
export const CONTEST_LEAVE = `${BASE_URL}/contest/leave`;
88
export const CONTEST_CREATE = `${BASE_URL}/contest/create`;
9-
export const CONTEST_RECENT = `${BASE_URL}/contest/recent`;
109
export const CONTEST_ITEM_UPDATE = `${BASE_URL}/contest/item/update`;
1110

1211
export const LIST_MY = `${BASE_URL}/list/my`;

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
import React from "react";
2-
import { connect, PromiseState } from "react-refetch";
32
import { Button, Col, Row } from "reactstrap";
43
import { useHistory } from "react-router-dom";
5-
import { useLoginState } from "../../../api/InternalAPIClient";
4+
import {
5+
useLoginState,
6+
useRecentContests,
7+
} from "../../../api/InternalAPIClient";
68
import { getCurrentUnixtimeInSecond } from "../../../utils/DateUtil";
79
import { VirtualContestTable } from "../VirtualContestTable";
8-
import { CONTEST_RECENT } from "../ApiUrl";
9-
import { VirtualContestInfo } from "../types";
1010

11-
interface InnerProps {
12-
contestListGet: PromiseState<VirtualContestInfo[]>;
13-
}
14-
15-
export const RecentContestList = connect<unknown, InnerProps>(() => ({
16-
contestListGet: {
17-
url: CONTEST_RECENT,
18-
},
19-
}))((props) => {
11+
export const RecentContestList = () => {
2012
const history = useHistory();
2113
const loginState = useLoginState();
22-
const contests = props.contestListGet.fulfilled
23-
? props.contestListGet.value.sort(
24-
(a, b) => b.start_epoch_second - a.start_epoch_second
25-
)
26-
: [];
14+
const contests =
15+
useRecentContests().data?.sort(
16+
(a, b) => b.start_epoch_second - a.start_epoch_second
17+
) ?? [];
2718
const now = getCurrentUnixtimeInSecond();
2819
const future = contests.filter((c) => c.start_epoch_second > now);
2920
const current = contests.filter(
@@ -104,4 +95,4 @@ export const RecentContestList = connect<unknown, InnerProps>(() => ({
10495
</Row>
10596
</>
10697
);
107-
});
98+
};

0 commit comments

Comments
 (0)