Hide negative earners on leaderboard. Show empty message if none on leaderboard.

This commit is contained in:
jahooma 2022-01-28 12:43:35 -06:00
parent 764790c1e1
commit 53a6748c6d
2 changed files with 40 additions and 35 deletions

View File

@ -17,6 +17,9 @@ 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} />
{users.length === 0 ? (
<div className="text-gray-500 ml-2">None yet</div>
) : (
<div className="overflow-x-auto"> <div className="overflow-x-auto">
<table className="table table-zebra table-compact text-gray-500 w-full"> <table className="table table-zebra table-compact text-gray-500 w-full">
<thead> <thead>
@ -54,6 +57,7 @@ export function Leaderboard(props: {
</tbody> </tbody>
</table> </table>
</div> </div>
)}
</div> </div>
) )
} }

View File

@ -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))
) )