-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff4a155
commit 9adb11a
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@import 'src/styles/subsocial-vars.scss' | ||
|
||
.LeaderboardTable | ||
display: grid | ||
grid-template-columns: max-content 1fr max-content | ||
column-gap: $space_small | ||
|
||
.LeaderboardTitles, :global(.infinite-scroll-component__outerdiv), :global(.infinite-scroll-component), :global(.ant-list), :global(.ant-list-items), :global(.ant-list-items) > li | ||
display: grid | ||
grid-template-columns: subgrid | ||
grid-column: 1/4 | ||
gap: $space_small | ||
align-items: center | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import clsx from 'clsx' | ||
import { ComponentProps, useState } from 'react' | ||
import { useSelectProfile } from 'src/rtk/app/hooks' | ||
import { wait } from 'src/utils/promise' | ||
import { InfiniteListByPage } from '../lists' | ||
import Avatar from '../profiles/address-views/Avatar' | ||
import { MutedSpan } from '../utils/MutedText' | ||
import styles from './LeaderboardTable.module.sass' | ||
|
||
export type LeaderboardTableProps = ComponentProps<'div'> & {} | ||
|
||
type Data = { rank: number; address: string; reward: number } | ||
const data: Data = { | ||
rank: 1, | ||
address: '3tJYxJN55FtVeZgX4WdwieZXDp4HF62TRVj11tY2aXHdrYus', | ||
reward: 202, | ||
} | ||
|
||
export default function LeaderboardTable({ ...props }: LeaderboardTableProps) { | ||
const [allData] = useState(() => | ||
Array.from({ length: 10 }).map((_, idx) => ({ ...data, rank: idx + 1 })), | ||
) | ||
|
||
const loadMore = async () => { | ||
await wait(1000) | ||
return Array.from({ length: 10 }).map((_, idx) => ({ ...data, rank: allData.length + idx + 1 })) | ||
} | ||
|
||
return ( | ||
<div | ||
{...props} | ||
className={clsx(styles.LeaderboardTable, 'FontWeightMedium FontSmall', props.className)} | ||
> | ||
<div className={clsx(styles.LeaderboardTitles, 'ColorMuted')}> | ||
<span>#</span> | ||
<span>Staker</span> | ||
<span>Rewards this week</span> | ||
</div> | ||
<InfiniteListByPage | ||
totalCount={100} | ||
getKey={(data: Data) => data.rank.toString()} | ||
dataSource={allData} | ||
loadMore={loadMore} | ||
renderItem={data => <UserRow data={data} key={data.rank} />} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
function UserRow({ data }: { data: Data }) { | ||
const profile = useSelectProfile(data.address) | ||
return ( | ||
<> | ||
<MutedSpan>{data.rank}</MutedSpan> | ||
<div className='d-flex align-items-center'> | ||
<Avatar address={data.address} avatar={profile?.content?.image} size={32} /> | ||
<span>{profile?.content?.name ?? 'Unnamed'}</span> | ||
</div> | ||
<span style={{ textAlign: 'right' }}>{data.reward} SUB</span> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters