-
-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathResetProgress.tsx
More file actions
90 lines (89 loc) · 3.06 KB
/
ResetProgress.tsx
File metadata and controls
90 lines (89 loc) · 3.06 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
import { Button, Col, Row, Table } from "reactstrap";
import React from "react";
import { GoTrashcan } from "react-icons/go";
import { useProblems } from "../../../api/APIClient";
import { ProblemSearchBox } from "../../../components/ProblemSearchBox";
import { ProblemLink } from "../../../components/ProblemLink";
import { formatMomentDateTime, parseSecond } from "../../../utils/DateUtil";
import { useProgressResetList } from "../../../api/InternalAPIClient";
import { ShowDifficultyMode } from "../../../utils/ShowDifficultyMode";
import { addResetProgress, deleteResetProgress } from "./ApiClient";
export const ResetProgress: React.FC = () => {
const progressResetListFetch = useProgressResetList();
const progressResetList = progressResetListFetch.data?.items || [];
progressResetList.sort((a, b) => a.reset_epoch_second - b.reset_epoch_second);
const problems = useProblems() ?? [];
return (
<>
<Row className="my-2">
<Col sm="12">
<h2>Reset Progress</h2>
</Col>
</Row>
<Row>
<Col sm="12">
<ProblemSearchBox
problems={problems}
selectProblem={async (problem) =>
await addResetProgress(problem.id).then(() =>
progressResetListFetch.mutate()
)
}
/>
</Col>
</Row>
<Row className="my-2">
<Col sm="12">
<Table>
<thead>
<tr>
<th>Problem</th>
<th>Reset at</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{progressResetList.map((item) => {
const problem = problems.find((p) => p.id === item.problem_id);
return (
<tr key={item.problem_id}>
<td>
{problem ? (
<ProblemLink
showDifficultyMode={ShowDifficultyMode.None}
problemId={problem.id}
contestId={problem.contest_id}
problemIndex={problem.problem_index}
problemName={problem.name}
/>
) : (
item.problem_id
)}
</td>
<td>
{formatMomentDateTime(
parseSecond(item.reset_epoch_second)
)}
</td>
<td>
<Button
color="danger"
onClick={async () =>
await deleteResetProgress(item.problem_id).then(() =>
progressResetListFetch.mutate()
)
}
>
<GoTrashcan />
</Button>
</td>
</tr>
);
})}
</tbody>
</Table>
</Col>
</Row>
</>
);
};