-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathindex.tsx
More file actions
executable file
·74 lines (65 loc) · 2.3 KB
/
index.tsx
File metadata and controls
executable file
·74 lines (65 loc) · 2.3 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
import React from "react";
import { Row } from "reactstrap";
import { useHistory, useLocation } from "react-router-dom";
import { useMultipleUserSubmissions } from "../../api/APIClient";
import {
useLoginState,
useProgressResetList,
} from "../../api/InternalAPIClient";
import { loggedInUserId } from "../../utils/UserState";
import { filterResetProgress } from "../Internal/types";
import { SmallTable } from "./SmallTable";
import { DifficultyTable } from "./DifficultyTable";
import { FilterParams, ProblemList } from "./ProblemList";
interface Props {
readonly userId: string;
readonly rivals: string[];
}
export const ListPage: React.FC<Props> = (props) => {
const location = useLocation();
const history = useHistory();
const users = [...props.rivals, props.userId];
const submissions = useMultipleUserSubmissions(users).data ?? [];
const progressReset = useProgressResetList().data;
const setPointFilter = (from: number, to: number): void => {
const params = new URLSearchParams(location.search);
params.set(FilterParams.FromPoint, from.toString());
params.set(FilterParams.ToPoint, to.toString());
history.push({ ...location, search: params.toString() });
};
const setDifficultyFilter = (from: number, to: number): void => {
const params = new URLSearchParams(location.search);
params.set(FilterParams.FromDifficulty, from.toString());
params.set(FilterParams.ToDifficulty, to.toString());
history.push({ ...location, search: params.toString() });
};
const loginState = useLoginState().data;
const loginUserId = loggedInUserId(loginState);
const filteredSubmissions =
progressReset && loginUserId
? filterResetProgress(submissions, progressReset, loginUserId)
: submissions;
return (
<div>
<Row className="my-2 border-bottom">
<h1>Point Status</h1>
</Row>
<Row>
<SmallTable
submissions={filteredSubmissions}
setFilterFunc={setPointFilter}
/>
</Row>
<Row className="my-2 border-bottom">
<h1>Difficulty Status</h1>
</Row>
<Row>
<DifficultyTable
submissions={filteredSubmissions}
setFilterFunc={setDifficultyFilter}
/>
</Row>
<ProblemList userId={props.userId} submissions={filteredSubmissions} />
</div>
);
};