| // src/components/dashboard/widgets/XPProgressWidget.tsx | |
| import type { XPLevel } from "@/types/dashboard"; | |
| import { Star, Award, TrendingUp, Zap, Sparkles } from "lucide-react"; | |
| import { useEffect, useRef, memo } from "react"; | |
| import confetti from "canvas-confetti"; | |
| interface XPProgressWidgetProps { | |
| data: XPLevel; | |
| } | |
| const LEVEL_TITLES = [ | |
| "Lab Assistant", "Junior Researcher", "Researcher", "Senior Researcher", | |
| "Postdoc", "Research Fellow", "Principal Investigator", "Distinguished Professor", | |
| ]; | |
| export const XPProgressWidget = memo(function XPProgressWidget({ data }: XPProgressWidgetProps) { | |
| const prevLevelRef = useRef(data.level); | |
| const progressPercent = Math.round((data.currentXP / data.xpToNextLevel) * 100); | |
| const nextLevelTitle = LEVEL_TITLES[Math.min(data.level, LEVEL_TITLES.length - 1)]; | |
| useEffect(() => { | |
| if (data.level > prevLevelRef.current) { | |
| // Level up! Fire confetti | |
| confetti({ particleCount: 150, spread: 100, origin: { y: 0.6 } }); | |
| } | |
| prevLevelRef.current = data.level; | |
| }, [data.level]); | |
| return ( | |
| <div className="flex items-center gap-4 h-full"> | |
| {/* Level badge with sparkle on level up */} | |
| <div className="relative shrink-0 w-16 h-16 rounded-2xl bg-gradient-to-br from-amber-400 to-orange-500 flex flex-col items-center justify-center text-white shadow-lg"> | |
| {data.level > prevLevelRef.current && ( | |
| <Sparkles className="absolute -top-2 -right-2 w-5 h-5 text-yellow-400 animate-ping" /> | |
| )} | |
| <Star className="w-5 h-5 mb-0.5" /> | |
| <span className="text-lg font-extrabold leading-none">{data.level}</span> | |
| </div> | |
| <div className="flex-1 min-w-0"> | |
| <div className="flex items-center justify-between mb-1"> | |
| <span className="text-sm font-bold text-gray-800 dark:text-gray-200">{data.title}</span> | |
| <span className="text-[10px] text-gray-400">{data.currentXP} / {data.xpToNextLevel} XP</span> | |
| </div> | |
| <div className="h-2.5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden"> | |
| <div className="h-full bg-gradient-to-r from-amber-400 to-orange-500 rounded-full transition-all" style={{ width: `${progressPercent}%` }} /> | |
| </div> | |
| <p className="text-[10px] text-gray-400 mt-1"> | |
| {data.xpToNextLevel - data.currentXP} XP until Level {data.level + 1} — {nextLevelTitle} | |
| </p> | |
| </div> | |
| <div className="shrink-0 space-y-1"> | |
| {data.recentEarnings.slice(0, 2).map((earning, i) => ( | |
| <div key={i} className="flex items-center gap-1.5 text-[10px]"> | |
| <span className="w-5 h-5 rounded-md bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center text-amber-700 dark:text-amber-400 font-bold"> | |
| +{earning.amount} | |
| </span> | |
| <span className="text-gray-500 truncate max-w-[100px]">{earning.reason}</span> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| }); |
Xet Storage Details
- Size:
- 2.95 kB
- Xet hash:
- fca3664b3854365dcf3e597ae52a9d0f30d8b5b7664ab5ae11de46b94db51f7d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.