Spaces:
Sleeping
Sleeping
File size: 11,092 Bytes
f871fed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
'use client'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Progress } from '@/components/ui/progress'
import { Badge } from '@/components/ui/badge'
import { useStudyStats, useFlashcardStats } from '@/lib/hooks/use-quiz'
import { LoadingSpinner } from '@/components/common/LoadingSpinner'
import {
Trophy,
Flame,
Target,
Brain,
Award,
TrendingUp,
Calendar,
Zap,
GraduationCap
} from 'lucide-react'
export function StudyStatsCard() {
const { data: stats, isLoading } = useStudyStats()
const { data: flashcardStats } = useFlashcardStats()
if (isLoading) {
return (
<div className="flex justify-center py-12">
<LoadingSpinner />
</div>
)
}
if (!stats) {
return (
<Card>
<CardContent className="py-12 text-center text-muted-foreground">
No study data yet. Start studying to see your progress!
</CardContent>
</Card>
)
}
const xpProgress = ((stats.total_xp % 500) / 500) * 100
const accuracyRate = stats.total_flashcards_reviewed > 0
? (stats.total_correct_answers / stats.total_flashcards_reviewed) * 100
: 0
return (
<div className="space-y-6">
{/* Summary Stats Row */}
<div className="grid gap-4 md:grid-cols-4">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Current Streak</CardTitle>
<Flame className="h-5 w-5 text-orange-500" />
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">{stats.current_streak} days</div>
<p className="text-xs text-muted-foreground mt-1">
Longest: {stats.longest_streak} days
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Level & XP</CardTitle>
<Trophy className="h-5 w-5 text-yellow-500" />
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">Level {stats.level}</div>
<p className="text-xs text-muted-foreground mt-1">
{stats.total_xp} Total XP
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Accuracy</CardTitle>
<Target className="h-5 w-5 text-green-500" />
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">{accuracyRate.toFixed(0)}%</div>
<p className="text-xs text-muted-foreground mt-1">
{stats.total_correct_answers} / {stats.total_flashcards_reviewed} correct
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Completed</CardTitle>
<GraduationCap className="h-5 w-5 text-blue-500" />
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">{stats.total_quizzes_completed}</div>
<p className="text-xs text-muted-foreground mt-1">
Quizzes taken
</p>
</CardContent>
</Card>
</div>
{/* Detailed Stats Grid */}
<div className="grid gap-6 md:grid-cols-2">
{/* XP & Level Card */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Zap className="h-5 w-5 text-yellow-500" />
Experience Points
</CardTitle>
<CardDescription>Your learning progress</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<div className="text-center">
<div className="inline-flex items-center justify-center w-24 h-24 rounded-full bg-gradient-to-br from-yellow-400 to-orange-500 text-white mb-4">
<div className="text-center">
<div className="text-2xl font-bold">Lv.{stats.level}</div>
</div>
</div>
<div className="text-3xl font-bold">{stats.total_xp} XP</div>
</div>
<div className="space-y-2">
<div className="flex justify-between text-sm">
<span className="text-muted-foreground">Progress to Level {stats.level + 1}</span>
<span>{500 - stats.xp_to_next_level} / 500 XP</span>
</div>
<Progress value={xpProgress} className="h-3" />
</div>
<div className="p-4 rounded-lg bg-muted/50">
<h4 className="font-medium mb-2 flex items-center gap-2">
<TrendingUp className="h-4 w-4" />
How to earn XP
</h4>
<ul className="text-sm text-muted-foreground space-y-1">
<li>• Complete a quiz: +50 XP</li>
<li>• Perfect quiz score: +100 XP</li>
<li>• Daily review: +25 XP</li>
<li>• Create flashcard: +10 XP</li>
<li>• Streak bonus: +10 XP per day</li>
</ul>
</div>
</CardContent>
</Card>
{/* Streak Card */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Flame className="h-5 w-5 text-orange-500" />
Study Streak
</CardTitle>
<CardDescription>Keep your momentum going!</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<div className="grid grid-cols-2 gap-4">
<div className="text-center p-4 rounded-lg bg-orange-500/10">
<Flame className="h-8 w-8 mx-auto text-orange-500 mb-2" />
<div className="text-3xl font-bold">{stats.current_streak}</div>
<div className="text-sm text-muted-foreground">Current Streak</div>
</div>
<div className="text-center p-4 rounded-lg bg-purple-500/10">
<Trophy className="h-8 w-8 mx-auto text-purple-500 mb-2" />
<div className="text-3xl font-bold">{stats.longest_streak}</div>
<div className="text-sm text-muted-foreground">Best Streak</div>
</div>
</div>
<div className="p-4 rounded-lg border">
<h4 className="font-medium mb-3 flex items-center gap-2">
<Calendar className="h-4 w-4" />
This Week
</h4>
<div className="flex justify-between">
{['M', 'T', 'W', 'T', 'F', 'S', 'S'].map((day, i) => (
<div key={i} className="text-center">
<div className="text-xs text-muted-foreground mb-1">{day}</div>
<div className={`w-8 h-8 rounded-full flex items-center justify-center ${
i < stats.current_streak
? 'bg-orange-500 text-white'
: 'bg-muted'
}`}>
{i < stats.current_streak ? '🔥' : ''}
</div>
</div>
))}
</div>
</div>
</CardContent>
</Card>
{/* Performance Stats */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Target className="h-5 w-5 text-blue-500" />
Performance
</CardTitle>
<CardDescription>Your learning metrics</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
<div className="flex items-center gap-3">
<Brain className="h-5 w-5 text-purple-500" />
<span>Quizzes Completed</span>
</div>
<span className="text-xl font-bold">{stats.total_quizzes_completed}</span>
</div>
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
<div className="flex items-center gap-3">
<Target className="h-5 w-5 text-green-500" />
<span>Cards Reviewed</span>
</div>
<span className="text-xl font-bold">{stats.total_flashcards_reviewed}</span>
</div>
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
<div className="flex items-center gap-3">
<TrendingUp className="h-5 w-5 text-blue-500" />
<span>Accuracy Rate</span>
</div>
<span className="text-xl font-bold">{accuracyRate.toFixed(0)}%</span>
</div>
</div>
</CardContent>
</Card>
{/* Badges Card */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Award className="h-5 w-5 text-yellow-500" />
Achievements
</CardTitle>
<CardDescription>Badges you've earned</CardDescription>
</CardHeader>
<CardContent>
{stats.badges && stats.badges.length > 0 ? (
<div className="flex flex-wrap gap-2">
{stats.badges.map((badge: string, i: number) => (
<Badge key={i} variant="secondary" className="text-sm py-1 px-3">
{badge}
</Badge>
))}
</div>
) : (
<div className="text-center py-8">
<Award className="h-12 w-12 mx-auto text-muted-foreground/50 mb-2" />
<p className="text-muted-foreground">No badges yet</p>
<p className="text-sm text-muted-foreground">
Complete quizzes and maintain streaks to earn badges!
</p>
</div>
)}
{/* Upcoming Badges Preview */}
<div className="mt-6 pt-4 border-t">
<h4 className="text-sm font-medium mb-3">Upcoming Badges</h4>
<div className="grid grid-cols-3 gap-2">
<div className="text-center p-2 rounded-lg bg-muted/30 opacity-50">
<div className="text-2xl mb-1">🎯</div>
<div className="text-xs">First Quiz</div>
</div>
<div className="text-center p-2 rounded-lg bg-muted/30 opacity-50">
<div className="text-2xl mb-1">🔥</div>
<div className="text-xs">7 Day Streak</div>
</div>
<div className="text-center p-2 rounded-lg bg-muted/30 opacity-50">
<div className="text-2xl mb-1">💯</div>
<div className="text-xs">Perfect Score</div>
</div>
</div>
</div>
</CardContent>
</Card>
</div>
</div>
)
}
|