File size: 10,286 Bytes
25732fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useEffect } from 'react'
import { motion } from 'framer-motion'
import { progressAPI, topicAPI } from '../../services/api'
import { 
  TrendingUp, 
  Target, 
  Award, 
  Brain,
  Calendar,
  Activity,
  Zap
} from 'lucide-react'
import KnowledgeGraph from './KnowledgeGraph'
import ProgressTimeline from './ProgressTimeline'
import toast from 'react-hot-toast'

const Progress = () => {
  const [loading, setLoading] = useState(true)
  const [summary, setSummary] = useState(null)
  const [topicProgress, setTopicProgress] = useState([])

  useEffect(() => {
    loadProgressData()
  }, [])

  const loadProgressData = async () => {
    try {
      setLoading(true)
      
      const [summaryRes, topicsRes] = await Promise.all([
        progressAPI.getProgressSummary(),
        topicAPI.getAll()
      ])

      setSummary(summaryRes.data)

      // Get knowledge state for each topic
      const progressPromises = topicsRes.data.map(async (topic) => {
        try {
          const stateRes = await progressAPI.getKnowledgeState(topic.id)
          return {
            ...topic,
            ...stateRes.data
          }
        } catch (err) {
          return {
            ...topic,
            knowledge_level: 0,
            confidence: 0,
            practice_count: 0
          }
        }
      })

      const progressData = await Promise.all(progressPromises)
      setTopicProgress(progressData)

    } catch (error) {
      toast.error('Failed to load progress data')
    } finally {
      setLoading(false)
    }
  }

  const container = {
    hidden: { opacity: 0 },
    show: {
      opacity: 1,
      transition: { staggerChildren: 0.1 }
    }
  }

  const item = {
    hidden: { y: 20, opacity: 0 },
    show: { y: 0, opacity: 1 }
  }

  if (loading) {
    return (
      <div className="flex items-center justify-center min-h-[60vh]">
        <div className="text-center">
          <div className="animate-spin rounded-full h-16 w-16 border-t-4 border-b-4 border-primary-600 mx-auto mb-4"></div>
          <p className="text-slate-600 font-medium">Loading your progress...</p>
        </div>
      </div>
    )
  }

  return (
    <motion.div
      variants={container}
      initial="hidden"
      animate="show"
      className="space-y-8"
    >
      {/* Header */}
      <motion.div variants={item} className="card bg-gradient-to-br from-primary-500 to-accent-600 text-white">
        <div className="flex items-center gap-4">
          <div className="w-16 h-16 bg-white/20 rounded-2xl flex items-center justify-center">
            <TrendingUp className="w-8 h-8" />
          </div>
          <div>
            <h1 className="text-3xl font-bold mb-2">
              Your Learning Progress
            </h1>
            <p className="text-primary-100">
              Track your journey and celebrate your achievements
            </p>
          </div>
        </div>
      </motion.div>

      {/* Summary Stats */}
      <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
        <motion.div variants={item} className="card group hover:shadow-2xl transition-shadow">
          <div className="flex items-center gap-4">
            <div className="w-14 h-14 bg-gradient-to-br from-green-500 to-emerald-500 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform">
              <Award className="w-7 h-7 text-white" />
            </div>
            <div>
              <div className="text-3xl font-bold text-slate-800">
                {summary?.topics_mastered || 0}
              </div>
              <div className="text-sm text-slate-600 font-medium">
                Topics Mastered
              </div>
            </div>
          </div>
        </motion.div>

        <motion.div variants={item} className="card group hover:shadow-2xl transition-shadow">
          <div className="flex items-center gap-4">
            <div className="w-14 h-14 bg-gradient-to-br from-blue-500 to-cyan-500 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform">
              <Brain className="w-7 h-7 text-white" />
            </div>
            <div>
              <div className="text-3xl font-bold text-slate-800">
                {summary?.topics_in_progress || 0}
              </div>
              <div className="text-sm text-slate-600 font-medium">
                In Progress
              </div>
            </div>
          </div>
        </motion.div>

        <motion.div variants={item} className="card group hover:shadow-2xl transition-shadow">
          <div className="flex items-center gap-4">
            <div className="w-14 h-14 bg-gradient-to-br from-purple-500 to-pink-500 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform">
              <Target className="w-7 h-7 text-white" />
            </div>
            <div>
              <div className="text-3xl font-bold text-slate-800">
                {Math.round((summary?.average_knowledge || 0) * 100)}%
              </div>
              <div className="text-sm text-slate-600 font-medium">
                Avg Knowledge
              </div>
            </div>
          </div>
        </motion.div>

        <motion.div variants={item} className="card group hover:shadow-2xl transition-shadow">
          <div className="flex items-center gap-4">
            <div className="w-14 h-14 bg-gradient-to-br from-orange-500 to-red-500 rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform">
              <Zap className="w-7 h-7 text-white" />
            </div>
            <div>
              <div className="text-3xl font-bold text-slate-800">
                {summary?.total_practice_count || 0}
              </div>
              <div className="text-sm text-slate-600 font-medium">
                Practice Sessions
              </div>
            </div>
          </div>
        </motion.div>
      </div>

      {/* Knowledge Graph */}
      <motion.div variants={item}>
        <KnowledgeGraph data={topicProgress} />
      </motion.div>

      {/* Weak and Strong Topics */}
      <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
        {/* Weak Topics */}
        <motion.div variants={item} className="card">
          <h2 className="text-2xl font-bold text-slate-800 mb-4 flex items-center gap-2">
            <Activity className="w-7 h-7 text-red-600" />
            Topics Needing Focus
          </h2>

          {summary?.weak_topics && summary.weak_topics.length > 0 ? (
            <div className="space-y-3">
              {summary.weak_topics.map((topic, index) => (
                <motion.div
                  key={topic.id}
                  initial={{ opacity: 0, x: -20 }}
                  animate={{ opacity: 1, x: 0 }}
                  transition={{ delay: index * 0.1 }}
                  className="p-4 bg-red-50 rounded-xl border border-red-100"
                >
                  <div className="flex items-center justify-between mb-2">
                    <span className="font-semibold text-slate-800">
                      {topic.name}
                    </span>
                    <span className="text-sm font-bold text-red-600">
                      {Math.round(topic.level * 100)}%
                    </span>
                  </div>
                  <div className="w-full bg-red-200 rounded-full h-2 overflow-hidden">
                    <motion.div
                      initial={{ width: 0 }}
                      animate={{ width: `${topic.level * 100}%` }}
                      transition={{ delay: 0.3 + (index * 0.1), duration: 0.8 }}
                      className="h-full bg-gradient-to-r from-red-500 to-orange-500 rounded-full"
                    />
                  </div>
                </motion.div>
              ))}
            </div>
          ) : (
            <div className="text-center py-8 text-slate-500">
              <Target className="w-12 h-12 mx-auto mb-2 opacity-50" />
              <p>No weak topics - great job!</p>
            </div>
          )}
        </motion.div>

        {/* Strong Topics */}
        <motion.div variants={item} className="card">
          <h2 className="text-2xl font-bold text-slate-800 mb-4 flex items-center gap-2">
            <Award className="w-7 h-7 text-green-600" />
            Strong Topics
          </h2>

          {summary?.strong_topics && summary.strong_topics.length > 0 ? (
            <div className="space-y-3">
              {summary.strong_topics.map((topic, index) => (
                <motion.div
                  key={topic.id}
                  initial={{ opacity: 0, x: 20 }}
                  animate={{ opacity: 1, x: 0 }}
                  transition={{ delay: index * 0.1 }}
                  className="p-4 bg-green-50 rounded-xl border border-green-100"
                >
                  <div className="flex items-center justify-between mb-2">
                    <span className="font-semibold text-slate-800">
                      {topic.name}
                    </span>
                    <span className="text-sm font-bold text-green-600">
                      {Math.round(topic.level * 100)}%
                    </span>
                  </div>
                  <div className="w-full bg-green-200 rounded-full h-2 overflow-hidden">
                    <motion.div
                      initial={{ width: 0 }}
                      animate={{ width: `${topic.level * 100}%` }}
                      transition={{ delay: 0.3 + (index * 0.1), duration: 0.8 }}
                      className="h-full bg-gradient-to-r from-green-500 to-emerald-500 rounded-full"
                    />
                  </div>
                </motion.div>
              ))}
            </div>
          ) : (
            <div className="text-center py-8 text-slate-500">
              <Brain className="w-12 h-12 mx-auto mb-2 opacity-50" />
              <p>Start learning to build strong topics</p>
            </div>
          )}
        </motion.div>
      </div>

      {/* Progress Timeline */}
      <motion.div variants={item}>
        <ProgressTimeline topics={topicProgress} />
      </motion.div>
    </motion.div>
  )
}

export default Progress