Make leaderboard not error on non-existant users

This commit is contained in:
James Grugett 2022-01-30 21:17:46 -06:00
parent f06ca8305c
commit 997f13d986

View File

@ -104,8 +104,14 @@ async function toUserScores(userScores: { [userId: string]: number }) {
const topUsers = await Promise.all(
topUserPairs.map(([userId]) => getUser(userId))
)
const topUserScores = topUserPairs.map(([_, score]) => score)
return [topUsers, topUserScores] as const
const existingPairs = topUserPairs.filter(([id, _]) =>
topUsers.find((user) => user?.id === id)
)
const topExistingUsers = existingPairs.map(
([id]) => topUsers.find((user) => user?.id === id) as User
)
const topUserScores = existingPairs.map(([_, score]) => score)
return [topExistingUsers, topUserScores] as const
}
export async function getStaticPaths() {