diff --git a/src/app/(app)/dashboard/page.tsx b/src/app/(app)/dashboard/page.tsx index e3be321..1d05cfc 100644 --- a/src/app/(app)/dashboard/page.tsx +++ b/src/app/(app)/dashboard/page.tsx @@ -112,6 +112,7 @@ export default async function DashboardPage() { .in('source', ['review', 'help_review']); const mentorPoints = mentorEvents?.reduce((acc, e) => acc + (e.xp_delta || 0), 0) || 0; + // Leaderboard // Leaderboard const { data: leaders } = await service .from('profiles') @@ -119,6 +120,28 @@ export default async function DashboardPage() { .order('xp', { ascending: false }) .limit(4); + // Get all profiles to calculate current user's rank + const { data: allProfiles } = await service + .from('profiles') + .select('github_handle, xp') + .order('xp', { ascending: false }); + + const currentUserRank = + allProfiles?.findIndex((p: any) => p.github_handle === profile?.github_handle) ?? -1; + + const myLeaderboardEntry = + currentUserRank >= 0 + ? { + github_handle: profile?.github_handle ?? 'You', + xp, + rank: currentUserRank + 1, + } + : null; + + const isUserVisible = leaders?.some( + (leader: any) => leader.github_handle === profile?.github_handle, + ); + // Mentees const { data: menteesData } = await service .from('help_requests') @@ -238,23 +261,64 @@ export default async function DashboardPage() {

- ACTIVE ISSUES + LEADERBOARD SNAPSHOT

- - BROWSE MORE - + + GLOBAL
- {recs.length > 0 ? ( - - ) : ( -
- No recommendations yet. Check back soon. -
- )} +
+ {leaders && leaders.length > 0 ? ( + <> + {leaders.map((leader: any, index: number) => { + const isMe = leader.github_handle === profile?.github_handle; + + return ( +
+
+ + {(index + 1).toString().padStart(2, '0')} + + {leader.github_handle} {isMe && '(YOU)'} +
+ + {leader.xp.toLocaleString()} XP +
+ ); + })} + + {!isUserVisible && myLeaderboardEntry && ( + <> +
+ + YOUR RANK + +
+ +
+
+ + {myLeaderboardEntry.rank.toString().padStart(2, '0')} + + {myLeaderboardEntry.github_handle} (YOU) +
+ + {myLeaderboardEntry.xp.toLocaleString()} XP +
+ + )} + + ) : ( +
+ Leaderboard is empty. +
+ )} +
diff --git a/src/app/(app)/leaderboard/page.tsx b/src/app/(app)/leaderboard/page.tsx index 1ceb434..55d4315 100644 --- a/src/app/(app)/leaderboard/page.tsx +++ b/src/app/(app)/leaderboard/page.tsx @@ -27,33 +27,80 @@ export default async function LeaderboardPage({