Skip to content

Commit 4ee6580

Browse files
committed
added user ratings and links to ranking pages
1 parent db320c7 commit 4ee6580

File tree

1 file changed

+82
-48
lines changed

1 file changed

+82
-48
lines changed

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

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from "react";
2-
import { Row } from "reactstrap";
2+
import { Row, Form, FormGroup, CustomInput } from "reactstrap";
33
import { BootstrapTable, TableHeaderColumn } from "react-bootstrap-table";
44
import { RankingEntry } from "../interfaces/RankingEntry";
5+
import { useLocalStorage } from "../utils/LocalStorage";
6+
import { UserNameLabel } from "./UserNameLabel";
57

68
interface Props {
79
title: React.ReactNode;
@@ -35,51 +37,68 @@ const refineRanking = (ranking: RankingEntry[]): InternalRankEntry[] =>
3537
return array;
3638
}, [] as InternalRankEntry[]);
3739

38-
export const Ranking: React.FC<Props> = (props) => (
39-
<Row>
40-
<h2>{props.title}</h2>
41-
<BootstrapTable
42-
height="auto"
43-
data={refineRanking(props.ranking)}
44-
pagination
45-
striped
46-
hover
47-
search
48-
options={{
49-
paginationPosition: "top",
50-
sizePerPage: 20,
51-
sizePerPageList: [
52-
{
53-
text: "20",
54-
value: 20,
55-
},
56-
{
57-
text: "50",
58-
value: 50,
59-
},
60-
{
61-
text: "100",
62-
value: 100,
63-
},
64-
{
65-
text: "200",
66-
value: 200,
67-
},
68-
{
69-
text: "All",
70-
value: props.ranking.length,
71-
},
72-
],
73-
}}
74-
>
75-
<TableHeaderColumn dataField="rank">#</TableHeaderColumn>
76-
<TableHeaderColumn dataField="id" isKey>
77-
User
78-
</TableHeaderColumn>
79-
<TableHeaderColumn dataField="count">Count</TableHeaderColumn>
80-
</BootstrapTable>
81-
</Row>
82-
);
40+
export const Ranking: React.FC<Props> = (props) => {
41+
const [showRating, setShowRating] = useLocalStorage("showRating", false);
42+
const usernameFormatter = (cell: string) => {
43+
return <UserNameLabel userId={cell} showRating={showRating} />;
44+
};
45+
return (
46+
<Row>
47+
<Form inline>
48+
<h2>{props.title}</h2>
49+
<FormGroup className="ml-3">
50+
<CustomInput
51+
type="switch"
52+
id="showRating"
53+
label="Show Rating"
54+
checked={showRating}
55+
onChange={(): void => setShowRating(!showRating)}
56+
/>
57+
</FormGroup>
58+
</Form>
59+
<BootstrapTable
60+
height="auto"
61+
data={refineRanking(props.ranking)}
62+
pagination
63+
striped
64+
hover
65+
search
66+
options={{
67+
paginationPosition: "top",
68+
sizePerPage: 20,
69+
sizePerPageList: [
70+
{
71+
text: "20",
72+
value: 20,
73+
},
74+
{
75+
text: "50",
76+
value: 50,
77+
},
78+
{
79+
text: "100",
80+
value: 100,
81+
},
82+
{
83+
text: "200",
84+
value: 200,
85+
},
86+
{
87+
text: "All",
88+
value: props.ranking.length,
89+
},
90+
],
91+
}}
92+
>
93+
<TableHeaderColumn dataField="rank">#</TableHeaderColumn>
94+
<TableHeaderColumn dataField="id" isKey dataFormat={usernameFormatter}>
95+
User
96+
</TableHeaderColumn>
97+
<TableHeaderColumn dataField="count">Count</TableHeaderColumn>
98+
</BootstrapTable>
99+
</Row>
100+
);
101+
};
83102

84103
const refineRankingWithOffset = (
85104
ranking: RankingEntry[],
@@ -140,9 +159,24 @@ export const RemoteRanking: React.FC<RemoteProps> = (props) => {
140159
});
141160
};
142161
const offset = (page - 1) * sizePerPage;
162+
const [showRating, setShowRating] = useLocalStorage("showRating", false);
163+
const usernameFormatter = (cell: string) => {
164+
return <UserNameLabel userId={cell} showRating={showRating} />;
165+
};
143166
return (
144167
<Row>
145-
<h2>{props.titleComponent}</h2>
168+
<Form inline>
169+
<h2>{props.titleComponent}</h2>
170+
<FormGroup className="ml-3">
171+
<CustomInput
172+
type="switch"
173+
id="showRating"
174+
label="Show Rating"
175+
checked={showRating}
176+
onChange={(): void => setShowRating(!showRating)}
177+
/>
178+
</FormGroup>
179+
</Form>
146180
<BootstrapTable
147181
height="auto"
148182
data={refineRankingWithOffset(
@@ -182,7 +216,7 @@ export const RemoteRanking: React.FC<RemoteProps> = (props) => {
182216
}}
183217
>
184218
<TableHeaderColumn dataField="rank">#</TableHeaderColumn>
185-
<TableHeaderColumn dataField="id" isKey>
219+
<TableHeaderColumn dataField="id" isKey dataFormat={usernameFormatter}>
186220
User
187221
</TableHeaderColumn>
188222
<TableHeaderColumn dataField="count">Count</TableHeaderColumn>

0 commit comments

Comments
 (0)