Skip to content

Commit

Permalink
Merge pull request #72 from aic-factcheck/migrate_fe
Browse files Browse the repository at this point in the history
fix pagination of leaderboard in user profile
  • Loading branch information
romanbutora committed Aug 14, 2023
2 parents 9da3541 + 4ec998c commit 78d519e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/Scoreboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ const Scoreboard: React.FC = () => {
const [stats, setStats] = useState<IStats>();
const [leaderboard, setLeaderboard] = useState([]);

const [currentPage, setCurrentPage] = useState(1);
const pageSize = 10; // Your page size

const columns = [
{
title: 'Rank',
render: (id: string, record: any, index: number) => { ++index; return index; },
render: (id: string, record: any, index: number) => {
const rank = (currentPage - 1) * pageSize + index + 1;
return rank;
},
},
{
title: t('name'),
Expand All @@ -40,6 +46,9 @@ const Scoreboard: React.FC = () => {
title: t('reputation'),
// eslint-disable-next-line no-useless-concat
dataIndex: 'reputation',
sorter: {
compare: (a: any, b: any) => a.reputation - b.reputation,
},
},
{
title: 'Level',
Expand Down Expand Up @@ -183,7 +192,16 @@ const Scoreboard: React.FC = () => {
<img alt="leaders" width="100%" src={`${process.env.PUBLIC_URL}/pictures/scoreboard.png`} style={{ padding: '5%' }} />
</Col>
<Col sm={18} style={{ overflowX: 'scroll' }}>
<Table columns={columns} dataSource={leaderboard} rowKey="id" />
<Table
columns={columns}
dataSource={leaderboard}
rowKey="id"
pagination={{
current: currentPage,
pageSize,
onChange: (page) => setCurrentPage(page),
}}
/>
</Col>
</Row>
</div>
Expand Down

0 comments on commit 78d519e

Please sign in to comment.