File size: 22,583 Bytes
78d0e31 |
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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
"use client"
import { useState, useEffect } from "react"
import { motion, AnimatePresence } from "framer-motion"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Progress } from "@/components/ui/progress"
import { Badge } from "@/components/ui/badge"
import { Textarea } from "@/components/ui/textarea"
import { BookOpen, Brain, Heart, Video, CheckCircle, Star, Zap, Trophy, Clock } from "lucide-react"
import { proverbValidator, type AfricanProverb } from "@/lib/proverb-validator"
interface Module {
id: string
title: string
description: string
type: "interactive" | "quiz" | "story" | "video"
difficulty: "beginner" | "intermediate" | "advanced"
rewardFLB: number
rewardXP: number
estimatedTime: number
completed: boolean
content?: any
}
interface QuizQuestion {
question: string
options: string[]
correctAnswer: number
explanation: string
proverb?: AfricanProverb
}
interface UserProgress {
totalXP: number
totalFLB: number
completedModules: string[]
currentStreak: number
storiesShared: number
}
const mockModules: Module[] = [
{
id: "akan-wisdom-1",
title: "Akan Wisdom: Sankofa Philosophy",
description: "Learn the profound meaning of looking back to move forward",
type: "interactive",
difficulty: "beginner",
rewardFLB: 25,
rewardXP: 50,
estimatedTime: 15,
completed: false,
content: {
proverb: "Se wo were fi na wosankofa a yenkyi",
language: "Akan",
meaning: "It is not wrong to go back for that which you have forgotten",
culturalContext:
"Sankofa teaches us to learn from the past to move forward wisely. The symbol shows a bird looking backward while moving forward.",
modernApplication:
"In today's fast-paced world, Sankofa reminds us to honor our ancestors' wisdom while embracing progress.",
},
},
{
id: "ubuntu-philosophy-1",
title: "Ubuntu: I Am Because We Are",
description: "Explore the foundational African philosophy of interconnectedness",
type: "interactive",
difficulty: "beginner",
rewardFLB: 30,
rewardXP: 60,
estimatedTime: 20,
completed: false,
content: {
proverb: "Ubuntu ngumuntu ngabantu",
language: "Zulu",
meaning: "I am because we are",
culturalContext:
"Ubuntu emphasizes our shared humanity and interconnectedness. Individual well-being is tied to community well-being.",
modernApplication:
"Ubuntu principles guide community building, conflict resolution, and social justice in modern Africa.",
},
},
{
id: "health-advocacy-1",
title: "Community Health Leadership",
description: "Learn how to advocate for health in African communities",
type: "video",
difficulty: "intermediate",
rewardFLB: 40,
rewardXP: 80,
estimatedTime: 25,
completed: false,
content: {
topics: ["Primary Healthcare", "Community Mobilization", "Health Education", "Disease Prevention"],
practicalSkills: ["Health Screening", "Community Outreach", "Health Data Collection", "Emergency Response"],
},
},
{
id: "proverb-mastery-quiz",
title: "African Proverbs Mastery Quiz",
description: "Test your knowledge of African wisdom across cultures",
type: "quiz",
difficulty: "intermediate",
rewardFLB: 35,
rewardXP: 70,
estimatedTime: 10,
completed: false,
content: {
questions: 5,
themes: ["wisdom", "community", "patience", "humility", "healing"],
},
},
]
export default function LearnEarnSystem() {
const [modules, setModules] = useState<Module[]>(mockModules)
const [currentModule, setCurrentModule] = useState<Module | null>(null)
const [userProgress, setUserProgress] = useState<UserProgress>({
totalXP: 0,
totalFLB: 0,
completedModules: [],
currentStreak: 0,
storiesShared: 0,
})
const [quizAnswers, setQuizAnswers] = useState<number[]>([])
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)
const [quizQuestions, setQuizQuestions] = useState<QuizQuestion[]>([])
const [storyContent, setStoryContent] = useState("")
const [showResults, setShowResults] = useState(false)
useEffect(() => {
// Generate quiz questions when quiz module is selected
if (currentModule?.type === "quiz") {
generateQuizQuestions()
}
}, [currentModule])
const generateQuizQuestions = () => {
const questions: QuizQuestion[] = []
for (let i = 0; i < 5; i++) {
const challenge = proverbValidator.generateProverbChallenge()
questions.push({
question: challenge.question,
options: challenge.options,
correctAnswer: challenge.correctAnswer,
explanation: `This ${challenge.proverb.language} proverb from ${challenge.proverb.country} teaches us: ${challenge.proverb.cultural_notes}`,
proverb: challenge.proverb,
})
}
setQuizQuestions(questions)
setQuizAnswers(new Array(questions.length).fill(-1))
setCurrentQuestionIndex(0)
}
const startModule = (module: Module) => {
setCurrentModule(module)
setShowResults(false)
if (module.type === "quiz") {
generateQuizQuestions()
}
}
const completeModule = (moduleId: string) => {
const module = modules.find((m) => m.id === moduleId)
if (!module) return
setModules((prev) => prev.map((m) => (m.id === moduleId ? { ...m, completed: true } : m)))
setUserProgress((prev) => ({
...prev,
totalXP: prev.totalXP + module.rewardXP,
totalFLB: prev.totalFLB + module.rewardFLB,
completedModules: [...prev.completedModules, moduleId],
currentStreak: prev.currentStreak + 1,
}))
setCurrentModule(null)
setShowResults(true)
}
const submitQuizAnswer = (questionIndex: number, answerIndex: number) => {
const newAnswers = [...quizAnswers]
newAnswers[questionIndex] = answerIndex
setQuizAnswers(newAnswers)
}
const finishQuiz = () => {
if (!currentModule) return
const correctAnswers = quizAnswers.reduce((count, answer, index) => {
return answer === quizQuestions[index]?.correctAnswer ? count + 1 : count
}, 0)
const passingScore = Math.ceil(quizQuestions.length * 0.7) // 70% to pass
if (correctAnswers >= passingScore) {
completeModule(currentModule.id)
} else {
// Allow retry
setCurrentQuestionIndex(0)
setQuizAnswers(new Array(quizQuestions.length).fill(-1))
}
}
const submitStory = () => {
if (!currentModule || storyContent.length < 100) return
setUserProgress((prev) => ({
...prev,
storiesShared: prev.storiesShared + 1,
}))
completeModule(currentModule.id)
setStoryContent("")
}
const getDifficultyColor = (difficulty: string) => {
switch (difficulty) {
case "beginner":
return "text-green-400"
case "intermediate":
return "text-yellow-400"
case "advanced":
return "text-red-400"
default:
return "text-gray-400"
}
}
const getTypeIcon = (type: string) => {
switch (type) {
case "interactive":
return <BookOpen className="w-5 h-5" />
case "quiz":
return <Brain className="w-5 h-5" />
case "story":
return <Heart className="w-5 h-5" />
case "video":
return <Video className="w-5 h-5" />
default:
return <BookOpen className="w-5 h-5" />
}
}
if (currentModule) {
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white p-6">
<div className="max-w-4xl mx-auto">
{/* Module Header */}
<div className="mb-8">
<Button variant="outline" onClick={() => setCurrentModule(null)} className="mb-4">
← Back to Modules
</Button>
<div className="flex items-center gap-3 mb-4">
{getTypeIcon(currentModule.type)}
<h1 className="text-3xl font-bold">{currentModule.title}</h1>
<Badge className={getDifficultyColor(currentModule.difficulty)}>{currentModule.difficulty}</Badge>
</div>
<p className="text-slate-300 text-lg">{currentModule.description}</p>
<div className="flex items-center gap-6 mt-4 text-sm text-slate-400">
<div className="flex items-center gap-1">
<Clock className="w-4 h-4" />
{currentModule.estimatedTime} min
</div>
<div className="flex items-center gap-1">
<Zap className="w-4 h-4" />+{currentModule.rewardFLB} FLB
</div>
<div className="flex items-center gap-1">
<Star className="w-4 h-4" />+{currentModule.rewardXP} XP
</div>
</div>
</div>
{/* Module Content */}
<Card className="bg-slate-800 border-slate-700">
<CardContent className="p-8">
{currentModule.type === "interactive" && (
<div className="space-y-6">
<div className="text-center">
<h2 className="text-2xl font-bold text-orange-400 mb-4">"{currentModule.content.proverb}"</h2>
<p className="text-lg text-slate-300 mb-2">{currentModule.content.meaning}</p>
<Badge className="mb-6">{currentModule.content.language}</Badge>
</div>
<div className="grid md:grid-cols-2 gap-6">
<div>
<h3 className="text-xl font-semibold text-blue-400 mb-3">Cultural Context</h3>
<p className="text-slate-300">{currentModule.content.culturalContext}</p>
</div>
<div>
<h3 className="text-xl font-semibold text-green-400 mb-3">Modern Application</h3>
<p className="text-slate-300">{currentModule.content.modernApplication}</p>
</div>
</div>
<div className="text-center pt-6">
<Button
onClick={() => completeModule(currentModule.id)}
className="bg-orange-600 hover:bg-orange-700"
>
Complete Module
</Button>
</div>
</div>
)}
{currentModule.type === "quiz" && quizQuestions.length > 0 && (
<div className="space-y-6">
<div className="flex justify-between items-center">
<h2 className="text-xl font-bold">
Question {currentQuestionIndex + 1} of {quizQuestions.length}
</h2>
<Progress value={((currentQuestionIndex + 1) / quizQuestions.length) * 100} className="w-32" />
</div>
{currentQuestionIndex < quizQuestions.length && (
<div className="space-y-4">
<h3 className="text-lg font-semibold text-white">
{quizQuestions[currentQuestionIndex].question}
</h3>
<div className="grid gap-3">
{quizQuestions[currentQuestionIndex].options.map((option, index) => (
<Button
key={index}
variant={quizAnswers[currentQuestionIndex] === index ? "default" : "outline"}
className="text-left justify-start p-4 h-auto"
onClick={() => submitQuizAnswer(currentQuestionIndex, index)}
>
{String.fromCharCode(65 + index)}) {option}
</Button>
))}
</div>
<div className="flex justify-between pt-4">
<Button
variant="outline"
disabled={currentQuestionIndex === 0}
onClick={() => setCurrentQuestionIndex((prev) => prev - 1)}
>
Previous
</Button>
{currentQuestionIndex === quizQuestions.length - 1 ? (
<Button
onClick={finishQuiz}
disabled={quizAnswers.includes(-1)}
className="bg-green-600 hover:bg-green-700"
>
Submit Quiz
</Button>
) : (
<Button
onClick={() => setCurrentQuestionIndex((prev) => prev + 1)}
disabled={quizAnswers[currentQuestionIndex] === -1}
>
Next
</Button>
)}
</div>
</div>
)}
</div>
)}
{currentModule.type === "story" && (
<div className="space-y-6">
<div>
<h2 className="text-xl font-bold text-purple-400 mb-4">Share Your Ubuntu Story</h2>
<p className="text-slate-300 mb-6">
Tell us about a time when you embodied the Ubuntu philosophy - "I am because we are". How did you
help someone or how did community support help you?
</p>
</div>
<div>
<Textarea
placeholder="Share your Ubuntu story here... (minimum 100 words)"
value={storyContent}
onChange={(e) => setStoryContent(e.target.value)}
className="min-h-[200px] bg-slate-700 border-slate-600"
/>
<div className="flex justify-between items-center mt-2">
<span className="text-sm text-slate-400">{storyContent.length} / 100 words minimum</span>
<span className={`text-sm ${storyContent.length >= 100 ? "text-green-400" : "text-slate-400"}`}>
{storyContent.length >= 100 ? "✓ Ready to submit" : "Keep writing..."}
</span>
</div>
</div>
<div className="text-center">
<Button
onClick={submitStory}
disabled={storyContent.length < 100}
className="bg-purple-600 hover:bg-purple-700"
>
Share Story & Earn Rewards
</Button>
</div>
</div>
)}
{currentModule.type === "video" && (
<div className="space-y-6">
<div className="aspect-video bg-slate-700 rounded-lg flex items-center justify-center">
<div className="text-center">
<Video className="w-16 h-16 mx-auto mb-4 text-slate-400" />
<p className="text-slate-400">Video content coming soon</p>
<p className="text-sm text-slate-500">Interactive health advocacy training</p>
</div>
</div>
<div>
<h3 className="text-lg font-semibold text-blue-400 mb-3">Learning Objectives</h3>
<ul className="space-y-2">
{currentModule.content.topics.map((topic: string, index: number) => (
<li key={index} className="flex items-center gap-2">
<CheckCircle className="w-4 h-4 text-green-400" />
<span className="text-slate-300">{topic}</span>
</li>
))}
</ul>
</div>
<div className="text-center">
<Button onClick={() => completeModule(currentModule.id)} className="bg-blue-600 hover:bg-blue-700">
Mark as Complete
</Button>
</div>
</div>
)}
</CardContent>
</Card>
</div>
</div>
)
}
return (
<div className="min-h-screen bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 text-white p-6">
<div className="max-w-6xl mx-auto">
{/* Header */}
<div className="text-center mb-12">
<h1 className="text-4xl md:text-6xl font-bold mb-4">
Learn & <span className="text-orange-400">Earn</span>
</h1>
<p className="text-xl text-slate-300 mb-8">
Master African wisdom, earn FLB tokens, and build Ubuntu community
</p>
{/* Progress Stats */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 max-w-2xl mx-auto">
<div className="bg-slate-800 rounded-lg p-4">
<div className="text-2xl font-bold text-orange-400">{userProgress.totalFLB}</div>
<div className="text-sm text-slate-400">FLB Earned</div>
</div>
<div className="bg-slate-800 rounded-lg p-4">
<div className="text-2xl font-bold text-blue-400">{userProgress.totalXP}</div>
<div className="text-sm text-slate-400">XP Gained</div>
</div>
<div className="bg-slate-800 rounded-lg p-4">
<div className="text-2xl font-bold text-green-400">{userProgress.completedModules.length}</div>
<div className="text-sm text-slate-400">Completed</div>
</div>
<div className="bg-slate-800 rounded-lg p-4">
<div className="text-2xl font-bold text-purple-400">{userProgress.storiesShared}</div>
<div className="text-sm text-slate-400">Stories Shared</div>
</div>
</div>
</div>
{/* Results Modal */}
<AnimatePresence>
{showResults && (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
onClick={() => setShowResults(false)}
>
<motion.div
initial={{ scale: 0.8, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.8, opacity: 0 }}
className="bg-slate-800 rounded-lg p-8 max-w-md mx-4"
onClick={(e) => e.stopPropagation()}
>
<div className="text-center">
<Trophy className="w-16 h-16 text-yellow-400 mx-auto mb-4" />
<h2 className="text-2xl font-bold text-white mb-2">Module Completed!</h2>
<p className="text-slate-300 mb-6">You've earned rewards for your learning</p>
<div className="space-y-2 mb-6">
<div className="flex justify-between">
<span>FLB Tokens:</span>
<span className="text-orange-400 font-bold">+{currentModule?.rewardFLB}</span>
</div>
<div className="flex justify-between">
<span>Experience:</span>
<span className="text-blue-400 font-bold">+{currentModule?.rewardXP} XP</span>
</div>
</div>
<Button onClick={() => setShowResults(false)} className="w-full">
Continue Learning
</Button>
</div>
</motion.div>
</motion.div>
)}
</AnimatePresence>
{/* Modules Grid */}
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{modules.map((module) => (
<motion.div key={module.id} whileHover={{ scale: 1.02 }} className="relative">
<Card
className={`bg-slate-800 border-slate-700 h-full ${module.completed ? "ring-2 ring-green-500" : ""}`}
>
<CardHeader>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
{getTypeIcon(module.type)}
<Badge className={getDifficultyColor(module.difficulty)}>{module.difficulty}</Badge>
</div>
{module.completed && <CheckCircle className="w-6 h-6 text-green-500" />}
</div>
<CardTitle className="text-white">{module.title}</CardTitle>
<CardDescription className="text-slate-300">{module.description}</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div className="flex items-center justify-between text-sm text-slate-400">
<div className="flex items-center gap-1">
<Clock className="w-4 h-4" />
{module.estimatedTime} min
</div>
<div className="flex items-center gap-3">
<div className="flex items-center gap-1">
<Zap className="w-4 h-4" />+{module.rewardFLB}
</div>
<div className="flex items-center gap-1">
<Star className="w-4 h-4" />+{module.rewardXP}
</div>
</div>
</div>
<Button
onClick={() => startModule(module)}
disabled={module.completed}
className={`w-full ${
module.completed ? "bg-green-600 hover:bg-green-700" : "bg-orange-600 hover:bg-orange-700"
}`}
>
{module.completed ? "Completed" : "Start Module"}
</Button>
</div>
</CardContent>
</Card>
</motion.div>
))}
</div>
</div>
</div>
)
}
|