Skip to content

Commit b490a3b

Browse files
add yes/no button
1 parent 4878d7f commit b490a3b

File tree

1 file changed

+56
-42
lines changed

1 file changed

+56
-42
lines changed

atcoder-problems-frontend/src/pages/ListPage/SmallTable.tsx

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from "react";
2-
import { Table } from "reactstrap";
1+
import React, { useState } from "react";
2+
import { Table, Button, ButtonGroup } from "reactstrap";
33
import { ProblemId } from "../../interfaces/Status";
44
import { isAccepted } from "../../utils";
55
import { countBy, groupBy } from "../../utils/GroupBy";
@@ -47,6 +47,7 @@ export const getUserPointCounts = (
4747
};
4848

4949
export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => {
50+
const [grouped, setGrouped] = useState(true);
5051
const mergedProblemMap =
5152
useMergedProblemMap().data ?? new Map<ProblemId, MergedProblem>();
5253
const userPointCountMap = getUserPointCounts(mergedProblemMap, submissions);
@@ -87,47 +88,60 @@ export const SmallTable: React.FC<Props> = ({ submissions, setFilterFunc }) => {
8788
);
8889

8990
return (
90-
<Table striped bordered hover responsive>
91-
<thead>
92-
<tr>
93-
<th>Point</th>
94-
{totalCountBy100.map(({ point }) => (
95-
<th key={point}>
96-
<a
97-
href={window.location.hash}
98-
onClick={(): void => setFilterFunc(point)}
99-
>
100-
{`${point}- `}
101-
</a>
102-
</th>
103-
))}
104-
</tr>
105-
<tr>
106-
<th>Total</th>
107-
{totalCountBy100.map(({ point, count }) => (
108-
<th key={point}>{count}</th>
109-
))}
110-
</tr>
111-
</thead>
112-
<tbody>
113-
{userPointCountMapBy100.map(({ userId, countByPoint }) => (
114-
<tr key={userId}>
115-
<td>{userId}</td>
116-
{totalCountBy100.map(({ point, count }) => (
117-
<td
118-
key={point}
119-
className={
120-
countByPoint.get(point) === count
121-
? TableColor.Success
122-
: TableColor.None
123-
}
124-
>
125-
{countByPoint.get(point) ?? 0}
126-
</td>
91+
<>
92+
<ButtonGroup className="mb-2">
93+
<Button onClick={(): void => setGrouped(!grouped)}>
94+
{grouped ? "Grouped" : "All"}
95+
</Button>
96+
</ButtonGroup>
97+
<Table striped bordered hover responsive>
98+
<thead>
99+
<tr>
100+
<th>Point</th>
101+
{(grouped ? totalCountBy100 : totalCount).map(({ point }) => (
102+
<th key={point}>
103+
<a
104+
href={window.location.hash}
105+
onClick={(): void => setFilterFunc(point)}
106+
>
107+
{`${point}- `}
108+
</a>
109+
</th>
127110
))}
128111
</tr>
129-
))}
130-
</tbody>
131-
</Table>
112+
<tr>
113+
<th>Total</th>
114+
{(grouped ? totalCountBy100 : totalCount).map(
115+
({ point, count }) => (
116+
<th key={point}>{count}</th>
117+
)
118+
)}
119+
</tr>
120+
</thead>
121+
<tbody>
122+
{(grouped ? userPointCountMapBy100 : userPointCountMap).map(
123+
({ userId, countByPoint }) => (
124+
<tr key={userId}>
125+
<td>{userId}</td>
126+
{(grouped ? totalCountBy100 : totalCount).map(
127+
({ point, count }) => (
128+
<td
129+
key={point}
130+
className={
131+
countByPoint.get(point) === count
132+
? TableColor.Success
133+
: TableColor.None
134+
}
135+
>
136+
{countByPoint.get(point) ?? 0}
137+
</td>
138+
)
139+
)}
140+
</tr>
141+
)
142+
)}
143+
</tbody>
144+
</Table>
145+
</>
132146
);
133147
};

0 commit comments

Comments
 (0)