fix leaderboard when current user doesn't have stats (#1289)

This commit is contained in:
notmd
2023-02-07 14:17:21 +07:00
committed by GitHub
parent 201a9669e0
commit 5d10b28b20
2 changed files with 3 additions and 3 deletions
@@ -34,7 +34,7 @@ export const LeaderboardTable = ({
data: reply,
isLoading,
error,
} = useSWRImmutable<LeaderboardReply & { user_stats_window: LeaderboardReply["leaderboard"] }>(
} = useSWRImmutable<LeaderboardReply & { user_stats_window?: LeaderboardReply["leaderboard"] }>(
`/api/leaderboard?time_frame=${timeFrame}&limit=${limit}&includeUserStats=${!hideCurrentUserRanking}`,
get
);
@@ -79,7 +79,7 @@ export const LeaderboardTable = ({
const start = (page - 1) * rowPerPage;
const end = start + rowPerPage;
const leaderBoardEntities = reply.leaderboard.slice(start, end);
if (hideCurrentUserRanking) {
if (hideCurrentUserRanking || !reply.user_stats_window) {
return leaderBoardEntities;
}
const userStatsWindow: WindowLeaderboardEntity[] = reply.user_stats_window;
+1 -1
View File
@@ -29,7 +29,7 @@ const handler = withoutRole("banned", async (req, res, token) => {
res.status(200).json({
...leaderboard,
user_stats_window: user_stats.leaderboard.map((stats) => ({ ...stats, is_window: true })),
user_stats_window: user_stats?.leaderboard.map((stats) => ({ ...stats, is_window: true })),
});
});