mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-29 16:30:24 +08:00
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user