From 9f2efc5872893e9cf27840bdb8848b37396a063a Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Tue, 1 Oct 2024 19:31:04 +0100 Subject: [PATCH] UI for leaderboard --- src/api/leaderboard.ts | 12 +- .../Leaderboard/LeaderboardPage.tsx | 156 ++++++++---------- 2 files changed, 75 insertions(+), 93 deletions(-) diff --git a/src/api/leaderboard.ts b/src/api/leaderboard.ts index 1ba6131c6..5e87b120f 100644 --- a/src/api/leaderboard.ts +++ b/src/api/leaderboard.ts @@ -1,7 +1,7 @@ import { type APIContext } from 'astro'; import { api } from './api.ts'; -export type LeadeboardUserDetails = { +export type LeaderboardUserDetails = { id: string; name: string; avatar?: string; @@ -10,15 +10,15 @@ export type LeadeboardUserDetails = { export type ListLeaderboardStatsResponse = { streaks: { - active: LeadeboardUserDetails[]; - lifetime: LeadeboardUserDetails[]; + active: LeaderboardUserDetails[]; + lifetime: LeaderboardUserDetails[]; }; projectSubmissions: { - currentMonth: LeadeboardUserDetails[]; - lifetime: LeadeboardUserDetails[]; + currentMonth: LeaderboardUserDetails[]; + lifetime: LeaderboardUserDetails[]; }; githubContributors: { - currentMonth: LeadeboardUserDetails[]; + currentMonth: LeaderboardUserDetails[]; }; }; diff --git a/src/components/Leaderboard/LeaderboardPage.tsx b/src/components/Leaderboard/LeaderboardPage.tsx index ba0da269e..63a268779 100644 --- a/src/components/Leaderboard/LeaderboardPage.tsx +++ b/src/components/Leaderboard/LeaderboardPage.tsx @@ -1,10 +1,10 @@ import { type ReactNode, useState } from 'react'; import type { - LeadeboardUserDetails, + LeaderboardUserDetails, ListLeaderboardStatsResponse, } from '../../api/leaderboard'; import { cn } from '../../lib/classname'; -import { FolderKanban, GitPullRequest, Trophy, Zap } from 'lucide-react'; +import { FolderKanban, GitPullRequest, Users2, Zap } from 'lucide-react'; import { TrophyEmoji } from '../ReactIcons/TrophyEmoji'; import { SecondPlaceMedalEmoji } from '../ReactIcons/SecondPlaceMedalEmoji'; import { ThirdPlaceMedalEmoji } from '../ReactIcons/ThirdPlaceMedalEmoji'; @@ -17,74 +17,60 @@ export function LeaderboardPage(props: LeaderboardPageProps) { const { stats } = props; return ( -
-
-
-
- party-popper -
-

- Leaderboard -

-

- Top users based on their activity on roadmap.sh -

-
-
- -
- , - emptyText: 'No users with streaks yet', - }, - { - title: 'Lifetime', - users: stats.streaks?.lifetime || [], - emptyIcon: , - emptyText: 'No users with streaks yet', - }, - ]} - /> - , - emptyText: 'No projects submitted this month', - }, - { - title: 'Lifetime', - users: stats.projectSubmissions.lifetime, - emptyIcon: , - emptyText: 'No projects submitted yet', - }, - ]} - /> - - ), - emptyText: 'No contributors this month', - }, - ]} - /> -
+
+
+

+ + Leaderboard +

+ +
+ , + emptyText: 'No users with streaks yet', + }, + { + title: 'Lifetime', + users: stats.streaks?.lifetime || [], + emptyIcon: , + emptyText: 'No users with streaks yet', + }, + ]} + /> + , + emptyText: 'No projects submitted this month', + }, + { + title: 'Lifetime', + users: stats.projectSubmissions.lifetime, + emptyIcon: , + emptyText: 'No projects submitted yet', + }, + ]} + /> + , + emptyText: 'No contributors this month', + }, + ]} + />
@@ -93,24 +79,30 @@ export function LeaderboardPage(props: LeaderboardPageProps) { type LeaderboardLaneProps = { title: string; + subtitle?: string; tabs: { title: string; - users: LeadeboardUserDetails[]; + users: LeaderboardUserDetails[]; emptyIcon?: ReactNode; emptyText?: string; }[]; }; function LeaderboardLane(props: LeaderboardLaneProps) { - const { title, tabs } = props; + const { title, subtitle, tabs } = props; const [activeTab, setActiveTab] = useState(tabs[0]); const { users: usersToShow, emptyIcon, emptyText } = activeTab; return ( -
-
-

{title}

+
+
+

+ {title}{' '} + {subtitle && ( + {subtitle} + )} +

{tabs.length > 1 && (
@@ -181,7 +173,7 @@ function LeaderboardLane(props: LeaderboardLaneProps) { /> {isGitHubUser ? ( @@ -201,17 +193,7 @@ function LeaderboardLane(props: LeaderboardLaneProps) { )}
- {isGitHubUser ? ( - - {user.count} - - ) : ( - {user.count} - )} + {user.count} ); })}