From 997f13d986dc2064eb706dd47c267eb2f9d5f63b Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 30 Jan 2022 21:17:46 -0600 Subject: [PATCH] Make leaderboard not error on non-existant users --- web/pages/fold/[...slugs]/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index 5d4a07a6..d5f905a4 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -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() {