import React from 'react'; import { Link } from 'react-router-dom'; import { useApp } from '../store/AppContext'; import Card from '../components/ui/Card'; import Button from '../components/ui/Button'; import Tag from '../components/ui/Tag'; import { storage } from '../lib/storage'; import { getAssignedTopic } from '../lib/learningService'; import { getTestResult } from '../lib/testService'; const Dashboard = () => { const { state } = useApp(); const { currentUser, weekNumber } = state; const topic = getAssignedTopic(currentUser?.id, weekNumber); const learnDone = storage.get(`user:${currentUser?.id}:week:${weekNumber}:learn_done`, false); const testResult = getTestResult(currentUser?.id, weekNumber); const leaderboard = storage.get('leaderboard:current', []).sort((a, b) => b.points - a.points); const top3 = leaderboard.slice(0, 3); const myRank = leaderboard.findIndex(u => u.userId === currentUser?.id) + 1; const myPoints = leaderboard.find(u => u.userId === currentUser?.id)?.points || 0; // Gather recent activity from past weeks const activity = []; for (let w = weekNumber; w >= Math.max(1, weekNumber - 3); w--) { const pastLearn = storage.get(`user:${currentUser?.id}:week:${w}:learn_done`, false); const pastTest = getTestResult(currentUser?.id, w); const pastTopic = getAssignedTopic(currentUser?.id, w); if (pastTest) { activity.push({ type: 'test', week: w, topic: pastTopic?.label, score: pastTest.percentage, points: pastTest.pointsEarned }); } if (pastLearn) { activity.push({ type: 'learn', week: w, topic: pastTopic?.label }); } } return (
Here is your overview for week {weekNumber}.
Your topic this week:
Weekly test — 10 questions
{act.type === 'test' ? 'Test completed' : 'Learning session'}: {act.topic}
Week {act.week} {act.type === 'test' && `· Score: ${act.score}%`}