From e2327295aff8a6b1d7b7b265b32a82ac2a8aacd2 Mon Sep 17 00:00:00 2001 From: AbdBarho Date: Tue, 7 Feb 2023 11:57:35 +0100 Subject: [PATCH] Fix error in user stats when loading (#1290) there was no check for waiting the data to be fetched, worked locally, not when deployed. --- website/src/pages/account/index.tsx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index 8a7753e1..27cc29fd 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -15,13 +15,17 @@ import uswSWRImmutable from "swr/immutable"; export default function Account() { const { t } = useTranslation("leaderboard"); const { data: session } = useSession(); - const { data } = uswSWRImmutable<{ [time in LeaderboardTimeFrame]: LeaderboardEntity }>("/api/user_stats", get); + const { data: entries } = uswSWRImmutable>( + "/api/user_stats", + get, + { + fallbackData: {}, + } + ); if (!session) { return; } - console.log(data); - return ( <> @@ -55,12 +59,10 @@ export default function Account() { LeaderboardTimeFrame.day, LeaderboardTimeFrame.week, LeaderboardTimeFrame.month, - ].map((key) => { - const values = data[key]; - if (!values) { - return null; - } - return ( + ] + .map((key) => ({ key, values: entries[key] })) + .filter(({ values }) => values) + .map(({ key, values }) => ( {t(getTypeSafei18nKey(key))} @@ -84,8 +86,7 @@ export default function Account() { - ); - })} + ))}