Hide negative earners on leaderboard. Show empty message if none on leaderboard.
This commit is contained in:
parent
764790c1e1
commit
53a6748c6d
|
@ -17,43 +17,47 @@ export function Leaderboard(props: {
|
||||||
return (
|
return (
|
||||||
<div className={clsx('w-full px-1', className)}>
|
<div className={clsx('w-full px-1', className)}>
|
||||||
<Title text={title} />
|
<Title text={title} />
|
||||||
<div className="overflow-x-auto">
|
{users.length === 0 ? (
|
||||||
<table className="table table-zebra table-compact text-gray-500 w-full">
|
<div className="text-gray-500 ml-2">None yet</div>
|
||||||
<thead>
|
) : (
|
||||||
<tr className="p-2">
|
<div className="overflow-x-auto">
|
||||||
<th>#</th>
|
<table className="table table-zebra table-compact text-gray-500 w-full">
|
||||||
<th>Name</th>
|
<thead>
|
||||||
{columns.map((column) => (
|
<tr className="p-2">
|
||||||
<th key={column.header}>{column.header}</th>
|
<th>#</th>
|
||||||
))}
|
<th>Name</th>
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{users.map((user, index) => (
|
|
||||||
<tr key={user.id}>
|
|
||||||
<td>{index + 1}</td>
|
|
||||||
<td>
|
|
||||||
<SiteLink className="relative" href={`/${user.username}`}>
|
|
||||||
<Row className="items-center gap-4">
|
|
||||||
<img
|
|
||||||
className="rounded-full bg-gray-400 flex-shrink-0 ring-8 ring-gray-50"
|
|
||||||
src={user.avatarUrl || ''}
|
|
||||||
alt=""
|
|
||||||
width={32}
|
|
||||||
height={32}
|
|
||||||
/>
|
|
||||||
<div className="truncate">{user.name}</div>
|
|
||||||
</Row>
|
|
||||||
</SiteLink>
|
|
||||||
</td>
|
|
||||||
{columns.map((column) => (
|
{columns.map((column) => (
|
||||||
<td key={column.header}>{column.renderCell(user)}</td>
|
<th key={column.header}>{column.header}</th>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
</thead>
|
||||||
</tbody>
|
<tbody>
|
||||||
</table>
|
{users.map((user, index) => (
|
||||||
</div>
|
<tr key={user.id}>
|
||||||
|
<td>{index + 1}</td>
|
||||||
|
<td>
|
||||||
|
<SiteLink className="relative" href={`/${user.username}`}>
|
||||||
|
<Row className="items-center gap-4">
|
||||||
|
<img
|
||||||
|
className="rounded-full bg-gray-400 flex-shrink-0 ring-8 ring-gray-50"
|
||||||
|
src={user.avatarUrl || ''}
|
||||||
|
alt=""
|
||||||
|
width={32}
|
||||||
|
height={32}
|
||||||
|
/>
|
||||||
|
<div className="truncate">{user.name}</div>
|
||||||
|
</Row>
|
||||||
|
</SiteLink>
|
||||||
|
</td>
|
||||||
|
{columns.map((column) => (
|
||||||
|
<td key={column.header}>{column.renderCell(user)}</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,8 @@ async function toUserScores(userScores: { [userId: string]: number }) {
|
||||||
const topUserPairs = _.take(
|
const topUserPairs = _.take(
|
||||||
_.sortBy(Object.entries(userScores), ([_, score]) => -1 * score),
|
_.sortBy(Object.entries(userScores), ([_, score]) => -1 * score),
|
||||||
10
|
10
|
||||||
)
|
).filter(([_, score]) => score > 0)
|
||||||
|
|
||||||
const topUsers = await Promise.all(
|
const topUsers = await Promise.all(
|
||||||
topUserPairs.map(([userId]) => getUser(userId))
|
topUserPairs.map(([userId]) => getUser(userId))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user