Skip to content

Commit 5c071d4

Browse files
committed
refactor: remove reference to problem.title
1 parent 9fcd066 commit 5c071d4

File tree

21 files changed

+84
-62
lines changed

21 files changed

+84
-62
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ export const useContestToProblems = () => {
226226
const problem = problemMap?.get(problem_id);
227227
if (problem) {
228228
const problems = map.get(contest_id) ?? [];
229-
problems.push({
230-
...problem,
231-
title: `${problem_index}. ${problem.title.replace(/^.+?\. */, "")}`,
232-
});
229+
problems.push({ ...problem, problem_index });
233230
map.set(contest_id, problems);
234231
}
235232
return map;
@@ -261,10 +258,7 @@ export const useContestToMergedProblems = () => {
261258
const problem = problemMap?.get(problem_id);
262259
if (problem) {
263260
const problems = map.get(contest_id) ?? [];
264-
problems.push({
265-
...problem,
266-
title: `${problem_index}. ${problem.title.replace(/^..*?\./, "")}`,
267-
});
261+
problems.push({ ...problem, problem_index });
268262
map.set(contest_id, problems);
269263
}
270264
return map;

atcoder-problems-frontend/src/components/ProblemLink.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ interface Props {
1111
className?: string;
1212
problemId: string;
1313
contestId: string;
14-
problemTitle: string;
14+
problemIndex?: string;
15+
problemName: string;
1516
showDifficulty?: boolean;
1617
isExperimentalDifficulty?: boolean;
1718
showDifficultyUnavailable?: boolean;
@@ -25,13 +26,18 @@ export const ProblemLink: React.FC<Props> = (props) => {
2526
const {
2627
contestId,
2728
problemId,
28-
problemTitle,
29+
problemIndex,
30+
problemName,
2931
showDifficulty,
3032
isExperimentalDifficulty,
3133
showDifficultyUnavailable,
3234
problemModel,
3335
userRatingInfo,
3436
} = props;
37+
const problemTitle = problemIndex
38+
? `${problemIndex}. ${problemName}`
39+
: problemName;
40+
3541
const link = (
3642
<NewTabLink
3743
href={Url.formatProblemUrl(problemId, contestId)}

atcoder-problems-frontend/src/components/ProblemSearchBox.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const problemMatch = (text: string, problem: Problem): boolean => {
1717
.every(
1818
(word) =>
1919
(word.trim().length > 0 &&
20-
problem.title.toLowerCase().includes(word.toLowerCase())) ||
20+
problem.name.toLowerCase().includes(word.toLowerCase())) ||
2121
formatProblemUrl(problem.id, problem.contest_id)
2222
.toLowerCase()
2323
.includes(word.toLowerCase())
@@ -76,7 +76,9 @@ export const ProblemSearchBox: React.FC<Props> = (props) => {
7676
setFocusingId(-1);
7777
}}
7878
>
79-
<ListGroupItemHeading>{problem.title}</ListGroupItemHeading>
79+
<ListGroupItemHeading>
80+
{problem.problem_index}. {problem.name}
81+
</ListGroupItemHeading>
8082
<ListGroupItemText>
8183
{formatProblemUrl(problem.id, problem.contest_id)}
8284
</ListGroupItemText>

atcoder-problems-frontend/src/components/SubmissionListTable.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ export const SubmissionListTable: React.FC<Props> = (props) => {
2323
const { submissions, userRatingInfo } = props;
2424
const problems = useProblems() ?? [];
2525
const problemModels = useProblemModelMap();
26-
const titleMap = problems.reduce((map, p) => {
27-
map.set(p.id, p.title);
28-
return map;
29-
}, new Map<string, string>());
26+
const [problemIndexMap, nameMap] = problems.reduce(
27+
([problemIndexMap, nameMap], p) => {
28+
problemIndexMap.set(p.id, p.problem_index);
29+
nameMap.set(p.id, p.name);
30+
return [problemIndexMap, nameMap];
31+
},
32+
[new Map<string, string>(), new Map<string, string>()]
33+
);
3034

3135
const verdictOptions: { [_: string]: string } = Array.from(
3236
submissions.reduce((set, s) => {
@@ -56,7 +60,11 @@ export const SubmissionListTable: React.FC<Props> = (props) => {
5660
<BootstrapTable
5761
data={submissions
5862
.sort((a, b) => b.epoch_second - a.epoch_second)
59-
.map((s) => ({ title: titleMap.get(s.problem_id), ...s }))}
63+
.map((s) => ({
64+
problemIndex: problemIndexMap.get(s.problem_id) ?? "",
65+
name: nameMap.get(s.problem_id) ?? "",
66+
...s,
67+
}))}
6068
keyField="id"
6169
height="auto"
6270
hover
@@ -107,9 +115,9 @@ export const SubmissionListTable: React.FC<Props> = (props) => {
107115
<TableHeaderColumn
108116
filterFormatted
109117
dataSort
110-
dataField="title"
118+
dataField="name"
111119
dataFormat={(
112-
title: string | undefined,
120+
name: string | undefined,
113121
{ problem_id, contest_id }: Submission
114122
): React.ReactElement => (
115123
<ProblemLink
@@ -118,7 +126,8 @@ export const SubmissionListTable: React.FC<Props> = (props) => {
118126
}
119127
showDifficulty={true}
120128
problemId={problem_id}
121-
problemTitle={title || ""}
129+
problemIndex={problemIndexMap.get(problem_id) || ""}
130+
problemName={name || ""}
122131
contestId={contest_id}
123132
problemModel={problemModels?.get(problem_id) ?? null}
124133
userRatingInfo={userRatingInfo}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export default interface MergedProblem {
1111
// Basic information
1212
readonly id: string;
1313
readonly contest_id: string;
14-
readonly title: string;
14+
readonly problem_index: string;
15+
readonly name: string;
1516

1617
// Information for first AC
1718
readonly first_user_id: string | null;
@@ -39,7 +40,8 @@ export const isMergedProblem = (obj: unknown): obj is MergedProblem =>
3940
obj !== null &&
4041
hasPropertyAsType(obj, "id", isString) &&
4142
hasPropertyAsType(obj, "contest_id", isString) &&
42-
hasPropertyAsType(obj, "title", isString) &&
43+
hasPropertyAsType(obj, "problem_index", isString) &&
44+
hasPropertyAsType(obj, "name", isString) &&
4345
hasPropertyAsTypeOrNull(obj, "first_user_id", isString) &&
4446
hasPropertyAsTypeOrNull(obj, "first_contest_id", isString) &&
4547
hasPropertyAsTypeOrNull(obj, "first_submission_id", isNumber) &&

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { hasPropertyAsType, isString } from "../utils/TypeUtils";
44
export default interface Problem {
55
readonly id: string;
66
readonly contest_id: string;
7-
readonly title: string;
7+
readonly problem_index: string;
8+
readonly name: string;
89
}
910

1011
export const isProblem = (obj: unknown): obj is Problem =>
1112
hasPropertyAsType(obj, "id", isString) &&
1213
hasPropertyAsType(obj, "contest_id", isString) &&
13-
hasPropertyAsType(obj, "title", isString);
14+
hasPropertyAsType(obj, "problem_index", isString) &&
15+
hasPropertyAsType(obj, "name", isString);

atcoder-problems-frontend/src/pages/Internal/MyAccountPage/ResetProgress.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export const ResetProgress: React.FC = () => {
5252
<ProblemLink
5353
problemId={problem.id}
5454
contestId={problem.contest_id}
55-
problemTitle={problem.title}
55+
problemIndex={problem.problem_index}
56+
problemName={problem.name}
5657
/>
5758
) : (
5859
item.problem_id

atcoder-problems-frontend/src/pages/Internal/ProblemList/SingleProblemList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const ProblemEntry: React.FC<{
188188
<ListGroupItemHeading>
189189
{problem ? (
190190
<NewTabLink href={formatProblemUrl(problem.id, problem.contest_id)}>
191-
{problem.title}
191+
{problem.problem_index}. {problem.name}
192192
</NewTabLink>
193193
) : (
194194
item.problem_id

atcoder-problems-frontend/src/pages/Internal/VirtualContest/DraggableContestConfigProblemTable/ProblemCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const ProblemCell: React.FC<ProblemCellProps> = ({
2222
<ProblemLink
2323
problemId={problem.id}
2424
contestId={problem.contest_id}
25-
problemTitle={problem.title}
25+
problemIndex={problem.problem_index}
26+
problemName={problem.name}
2627
showDifficulty={true}
2728
problemModel={problemModel}
2829
isExperimentalDifficulty={problemModel?.is_experimental}

atcoder-problems-frontend/src/pages/Internal/VirtualContest/DraggableContestConfigProblemTable/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ export const DraggableContestConfigProblemTable: React.FC<Props> = (props) => {
8787
compare: (a: VirtualContestItem, b: VirtualContestItem): number => {
8888
const getTitle = (problemId: ProblemId): string => {
8989
const problem = problemMap?.get(problemId);
90-
const title = problem?.title ? problem.title : "";
90+
const title = `${problem?.problem_index ?? ""}. ${
91+
problem?.name ?? ""
92+
}`;
9193
return title;
9294
};
9395
const aTitle = getTitle(a.id);

0 commit comments

Comments
 (0)