-
Notifications
You must be signed in to change notification settings - Fork 30
feat: Add mini-leaderboard and user rank badge components #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0xdevcollins
merged 3 commits into
boundlessfi:main
from
Dprof-in-tech:feat-implement-reusable-min-leaderboard-component
Jan 30, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
1ec260f
feat: Add mini-leaderboard and user rank badge components, integrate …
Dprof-in-tech ea5c204
fix: improve avatar fallback handling for missing or empty display na…
Dprof-in-tech c5b195e
refactor: Update avatar fallback placeholder from "John Doe" to '?'.
Dprof-in-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| "use client"; | ||
|
|
||
| import { useTopContributors } from "@/hooks/use-leaderboard"; | ||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
| import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
| import { Skeleton } from "@/components/ui/skeleton"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { TierBadge } from "./tier-badge"; | ||
| import { Trophy, ChevronRight, AlertCircle } from "lucide-react"; | ||
| import Link from "next/link"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| interface MiniLeaderboardProps { | ||
| className?: string; | ||
| limit?: number; | ||
| title?: string; | ||
| } | ||
|
|
||
| export function MiniLeaderboard({ | ||
| className, | ||
| limit = 5, | ||
| title = "Top Contributors" | ||
| }: MiniLeaderboardProps) { | ||
| const { data: contributors, isLoading, error } = useTopContributors(limit); | ||
|
|
||
| if (error) { | ||
| // Quiet failure for sidebars - or minimal error state | ||
| return ( | ||
| <Card className={cn("border-border/50 bg-background-card", className)}> | ||
| <CardContent className="py-6 text-center text-white/70 text-sm flex flex-col items-center gap-2"> | ||
| <AlertCircle className="h-4 w-4" /> | ||
| <span>Failed to load leaderboard</span> | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Card className={cn("border-border/50 bg-background-card overflow-hidden", className)}> | ||
| <CardHeader className="pb-3 pt-4 px-4 flex flex-row items-center justify-between space-y-0"> | ||
| <CardTitle className="text-base font-semibold text-white flex items-center gap-2"> | ||
| <Trophy className="h-4 w-4 text-yellow-500" /> | ||
| {title} | ||
| </CardTitle> | ||
| <Link href="/leaderboard" className="text-xs text-white/70 hover:text-white transition-colors flex items-center"> | ||
| View All <ChevronRight className="h-3 w-3 ml-0.5" /> | ||
| </Link> | ||
| </CardHeader> | ||
| <CardContent className="p-0"> | ||
| {isLoading ? ( | ||
| <div className="space-y-1 p-2"> | ||
| {Array.from({ length: limit }).map((_, i) => ( | ||
| <div key={i} className="flex items-center gap-3 p-2"> | ||
| <Skeleton className="h-8 w-8 rounded-full" /> | ||
| <div className="space-y-1 flex-1"> | ||
| <Skeleton className="h-3 w-24" /> | ||
| <Skeleton className="h-2 w-16" /> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) : ( | ||
| <div className="flex flex-col"> | ||
| {contributors?.map((contributor, index) => ( | ||
| <Link | ||
| key={contributor.id} | ||
| href={`/profile/${contributor.userId}`} | ||
| className="flex items-center gap-3 px-4 py-3 hover:bg-muted/50 transition-colors border-b border-border/40 last:border-0 group" | ||
| > | ||
| <div className="flex-shrink-0 relative"> | ||
| <Avatar className="h-9 w-9 border border-border/50"> | ||
| <AvatarImage src={contributor.avatarUrl || undefined} /> | ||
| <AvatarFallback>{contributor.displayName[0]}</AvatarFallback> | ||
| </Avatar> | ||
| <div className="absolute -top-1 -left-1 text-white/70 flex items-center justify-center w-4 h-4 rounded-full bg-background border border-border text-[10px] font-bold"> | ||
| {index + 1} | ||
| </div> | ||
| </div> | ||
| <div className="flex-1 min-w-0"> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="font-medium text-white text-sm truncate group-hover:text-primary transition-colors"> | ||
| {contributor.displayName} | ||
| </span> | ||
| </div> | ||
| <div className="flex items-center gap-2 mt-0.5"> | ||
| <TierBadge tier={contributor.tier} className="h-4 text-[10px] px-1.5 py-0" /> | ||
| <span className="text-[10px] text-white/70 font-mono"> | ||
| {contributor.totalScore.toLocaleString()} pts | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </Link> | ||
| ))} | ||
| <div className="p-2"> | ||
| <Button variant="ghost" className="w-full text-xs h-8 text-white/70 hover:text-black" asChild> | ||
| <Link href="/leaderboard"> | ||
| See full rankings | ||
| </Link> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| "use client"; | ||
|
|
||
| import { useUserRank } from "@/hooks/use-leaderboard"; | ||
| import { Badge } from "@/components/ui/badge"; | ||
| import { Trophy } from "lucide-react"; | ||
| import { Skeleton } from "@/components/ui/skeleton"; | ||
| import Link from "next/link"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| interface NavRankBadgeProps { | ||
| userId?: string; | ||
| className?: string; | ||
| } | ||
|
|
||
| export function NavRankBadge({ userId, className }: NavRankBadgeProps) { | ||
| const { data, isLoading } = useUserRank(userId); | ||
|
|
||
| if (!userId) return null; | ||
|
|
||
| if (isLoading) { | ||
| return <Skeleton className="h-6 w-16 rounded-full" />; | ||
| } | ||
|
|
||
| if (!data || !data.rank) return null; | ||
|
|
||
| return ( | ||
| <Link href="/leaderboard"> | ||
| <Badge | ||
| variant="secondary" | ||
| className={cn( | ||
| "gap-1.5 pl-1.5 pr-2.5 py-0.5 hover:bg-secondary/80 transition-colors cursor-pointer", | ||
| className | ||
| )} | ||
| > | ||
| <div className="bg-yellow-500/10 text-yellow-500 rounded-full p-0.5"> | ||
| <Trophy className="h-3 w-3" /> | ||
| </div> | ||
| <span className="font-mono font-medium">#{data.rank}</span> | ||
| </Badge> | ||
| </Link> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.