Skip to content

Commit 0de882b

Browse files
committed
feat: update frontend to reflect change in problem_index
1 parent 9fd21cd commit 0de882b

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

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

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import {
1010
RankingEntry,
1111
SumRankingEntry,
1212
} from "../interfaces/RankingEntry";
13-
import { ContestId, ProblemId, UserId } from "../interfaces/Status";
13+
import {
14+
ContestId,
15+
ProblemId,
16+
ProblemIndex,
17+
UserId,
18+
} from "../interfaces/Status";
1419
import { isSubmission } from "../interfaces/Submission";
1520
import { isUserRankEntry, UserRankEntry } from "../interfaces/UserRankEntry";
1621
import { clipDifficulty, isValidResult } from "../utils";
@@ -203,18 +208,28 @@ export const useContestToProblems = () => {
203208
const contestIdToProblemIdArray = useSWRData(url, (url) =>
204209
fetchTypedArray(
205210
url,
206-
(obj): obj is { contest_id: ContestId; problem_id: ProblemId } =>
211+
(
212+
obj
213+
): obj is {
214+
contest_id: ContestId;
215+
problem_id: ProblemId;
216+
problem_index: ProblemIndex;
217+
} =>
207218
hasPropertyAsType(obj, "contest_id", isString) &&
208-
hasPropertyAsType(obj, "problem_id", isString)
219+
hasPropertyAsType(obj, "problem_id", isString) &&
220+
hasPropertyAsType(obj, "problem_index", isString)
209221
)
210222
);
211223
const problemMap = useProblemMap();
212224
return contestIdToProblemIdArray.data?.reduce(
213-
(map, { contest_id, problem_id }) => {
225+
(map, { contest_id, problem_id, problem_index }) => {
214226
const problem = problemMap?.get(problem_id);
215227
if (problem) {
216228
const problems = map.get(contest_id) ?? [];
217-
problems.push(problem);
229+
problems.push({
230+
...problem,
231+
title: `${problem_index}. ${problem.title.replace(/^.+?\. */, "")}`,
232+
});
218233
map.set(contest_id, problems);
219234
}
220235
return map;
@@ -228,18 +243,28 @@ export const useContestToMergedProblems = () => {
228243
const contestIdToProblemIdArray = useSWRData(url, (url) =>
229244
fetchTypedArray(
230245
url,
231-
(obj): obj is { contest_id: ContestId; problem_id: ProblemId } =>
246+
(
247+
obj
248+
): obj is {
249+
contest_id: ContestId;
250+
problem_id: ProblemId;
251+
problem_index: ProblemIndex;
252+
} =>
232253
hasPropertyAsType(obj, "contest_id", isString) &&
233-
hasPropertyAsType(obj, "problem_id", isString)
254+
hasPropertyAsType(obj, "problem_id", isString) &&
255+
hasPropertyAsType(obj, "problem_index", isString)
234256
)
235257
);
236258
const { data: problemMap } = useMergedProblemMap();
237259
return contestIdToProblemIdArray.data?.reduce(
238-
(map, { contest_id, problem_id }) => {
260+
(map, { contest_id, problem_id, problem_index }) => {
239261
const problem = problemMap?.get(problem_id);
240262
if (problem) {
241263
const problems = map.get(contest_id) ?? [];
242-
problems.push(problem);
264+
problems.push({
265+
...problem,
266+
title: `${problem_index}. ${problem.title.replace(/^..*?\./, "")}`,
267+
});
243268
map.set(contest_id, problems);
244269
}
245270
return map;

atcoder-problems-frontend/src/interfaces/Status.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { caseInsensitiveUserId, isAccepted } from "../utils";
22
import Submission from "./Submission";
33
export type ContestId = string;
44
export type ProblemId = string;
5+
export type ProblemIndex = string;
56
export type UserId = string;
67

78
export enum StatusLabel {

0 commit comments

Comments
 (0)