Fix error in user stats when loading (#1290)

there was no check for waiting the data to be fetched, worked locally, not when deployed.
This commit is contained in:
AbdBarho
2023-02-07 11:57:35 +01:00
committed by GitHub
parent b7d0c4331c
commit e2327295af
+12 -11
View File
@@ -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<Partial<{ [time in LeaderboardTimeFrame]: LeaderboardEntity }>>(
"/api/user_stats",
get,
{
fallbackData: {},
}
);
if (!session) {
return;
}
console.log(data);
return (
<>
<Head>
@@ -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 }) => (
<Box key={key} py={4}>
<Title>{t(getTypeSafei18nKey(key))}</Title>
<Flex w="full" wrap="wrap" alignItems="flex-start" gap={4}>
@@ -84,8 +86,7 @@ export default function Account() {
</TableColumn>
</Flex>
</Box>
);
})}
))}
</SurveyCard>
</Flex>
</main>