-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathContestTable.tsx
More file actions
152 lines (149 loc) · 5.48 KB
/
ContestTable.tsx
File metadata and controls
152 lines (149 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { Row, Table } from "reactstrap";
import React from "react";
import { useProblemModelMap } from "../../api/APIClient";
import Contest from "../../interfaces/Contest";
import MergedProblem from "../../interfaces/MergedProblem";
import { ProblemId, ProblemStatus, StatusLabel } from "../../interfaces/Status";
import { ColorMode, statusToTableColor } from "../../utils/TableColor";
import { ProblemLink } from "../../components/ProblemLink";
import { ContestLink } from "../../components/ContestLink";
import { SubmitTimespan } from "../../components/SubmitTimespan";
import { RatingInfo } from "../../utils/RatingInfo";
import { isRatedContest } from "../../utils/ContestClassifier";
import { ProblemPoint } from "../../components/Problempoint";
import { ShowDifficultyMode } from "../../utils/ShowDifficultyMode";
interface Props {
contests: Contest[];
contestToProblems: Map<string, MergedProblem[]>;
hideCompletedContest: boolean;
showDifficultyMode: ShowDifficultyMode;
colorMode: ColorMode;
statusLabelMap: Map<ProblemId, ProblemStatus>;
showPenalties: boolean;
selectedLanguages: Set<string>;
title: string;
userRatingInfo: RatingInfo;
}
export const convertProblemIndexForSorting = (
problem_index: string
): [string, number] => {
const str = problem_index.replace(/[0-9]/g, "");
const num = parseInt(problem_index.replace(/[^0-9]/g, ""), 10);
return [str, num];
};
export const ContestTable: React.FC<Props> = (props) => {
const {
contests,
contestToProblems,
hideCompletedContest,
statusLabelMap,
colorMode,
showPenalties,
selectedLanguages,
userRatingInfo,
} = props;
const problemModels = useProblemModelMap();
const mergedContests = contests
.sort((a, b) => b.start_epoch_second - a.start_epoch_second)
.map((contest) => ({
contest,
problems: (contestToProblems.get(contest.id) ?? []).sort((a, b) => {
const [str_a, num_a] = convertProblemIndexForSorting(a.problem_index);
const [str_b, num_b] = convertProblemIndexForSorting(b.problem_index);
const cmp = str_a.localeCompare(str_b);
return cmp === 0 ? num_a - num_b : cmp;
}),
}))
.map(({ contest, problems }) => {
const problemStatus = problems.map((p) => ({
problem: p,
status: statusLabelMap.get(p.id),
}));
return { contest, problemStatus };
})
.filter(
({ problemStatus }) =>
!hideCompletedContest ||
!problemStatus.every(
({ status }) => !!status && status.label === StatusLabel.Success
)
)
.map(({ contest, problemStatus }) => {
const problemInfo = problemStatus.map(({ problem, status }) => {
const model = problemModels?.get(problem.id);
return { problem, status, model };
});
return { contest, problemInfo };
});
return (
<>
<Row className="my-4">
<h2>{props.title}</h2>
</Row>
<div>
{mergedContests.map(({ contest, problemInfo }) => {
return (
<div key={contest.id} className="contest-table-responsive">
<strong>
<ContestLink contest={contest} />
</strong>
<Table striped bordered hover responsive>
<tbody>
<tr>
{problemInfo.map(({ problem, status, model }) => {
const color = status
? statusToTableColor({
colorMode,
status,
contest,
selectedLanguages,
})
: "";
const INF_POINT = 1e18;
const point = problem.point ?? INF_POINT;
return (
<td
key={problem.id}
className={["table-problem", color]
.filter((nm) => nm)
.join(" ")}
>
<ProblemLink
isExperimentalDifficulty={
model ? model.is_experimental : false
}
showDifficultyUnavailable={isRatedContest(
contest,
problemInfo.length
)}
showDifficultyMode={props.showDifficultyMode}
problemId={problem.id}
contestId={contest.id}
problemIndex={problem.problem_index}
problemName={problem.name}
problemModel={model}
userRatingInfo={userRatingInfo}
/>
{props.colorMode === ColorMode.None && (
<ProblemPoint point={point} />
)}
{props.colorMode === ColorMode.ContestResult && (
<SubmitTimespan
contest={contest}
problemStatus={status}
showPenalties={showPenalties}
/>
)}
</td>
);
})}
</tr>
</tbody>
</Table>
</div>
);
})}
</div>
</>
);
};