From 87da9d038a845d41e36b03e54ec8b50841b6c251 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Tue, 10 Sep 2024 20:26:51 +0600 Subject: [PATCH] feat: add empty and error pages --- .../Leaderboard/LeaderboardPage.tsx | 94 +++++++++++++------ 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/src/components/Leaderboard/LeaderboardPage.tsx b/src/components/Leaderboard/LeaderboardPage.tsx index 7ef194209..1e5873200 100644 --- a/src/components/Leaderboard/LeaderboardPage.tsx +++ b/src/components/Leaderboard/LeaderboardPage.tsx @@ -1,9 +1,10 @@ -import { useState } from 'react'; +import { useState, type ReactNode } from 'react'; import type { LeadeboardUserDetails, ListLeaderboardStatsResponse, } from '../../api/leaderboard'; import { cn } from '../../lib/classname'; +import { FolderKanban, Zap } from 'lucide-react'; type LeaderboardPageProps = { stats: ListLeaderboardStatsResponse; @@ -22,18 +23,32 @@ export function LeaderboardPage(props: LeaderboardPageProps) { Top users based on their activity on roadmap.sh

-
+
, + emptyText: 'No users with streaks yet', + }, + ]} /> , + emptyText: 'No projects submitted this month', + }, + { + title: 'Lifetime', + users: stats.projectSubmissions.lifetime, + emptyIcon: , + emptyText: 'No projects submitted yet', }, ]} /> @@ -48,6 +63,8 @@ type LeaderboardLaneProps = { tabs: { title: string; users: LeadeboardUserDetails[]; + emptyIcon?: ReactNode; + emptyText?: string; }[]; }; @@ -55,7 +72,7 @@ function LeaderboardLane(props: LeaderboardLaneProps) { const { title, tabs } = props; const [activeTab, setActiveTab] = useState(tabs[0]); - const usersToShow = activeTab.users; + const { users: usersToShow, emptyIcon, emptyText } = activeTab; return (
@@ -84,35 +101,50 @@ function LeaderboardLane(props: LeaderboardLaneProps) { )}
-
    - {usersToShow.map((user, counter) => { - const avatar = user?.avatar - ? `${import.meta.env.PUBLIC_AVATAR_BASE_URL}/${user.avatar}` - : '/images/default-avatar.png'; + {usersToShow.length === 0 && emptyText && ( +
    + {emptyIcon} +

    {emptyText}

    +
    + )} + + {usersToShow.length > 0 && ( +
      + {usersToShow.map((user, counter) => { + const avatar = user?.avatar + ? `${import.meta.env.PUBLIC_AVATAR_BASE_URL}/${user.avatar}` + : '/images/default-avatar.png'; + const rank = counter + 1; - return ( -
    • -
      - - {counter + 1} - + return ( +
    • +
      + + {rank} + - {user.name} - {user.name} -
      + {user.name} + {user.name} +
- {user.count} - - ); - })} - + {user.count} + + ); + })} + + )}
); }