Skip to content

Commit a40f127

Browse files
Copilotanshaneja5
andcommitted
Fix dashboard logic to show correct resource counts
Co-authored-by: anshaneja5 <128882734+anshaneja5@users.noreply.github.com>
1 parent 14021a4 commit a40f127

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

src/components/LearnerDashboard.jsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { Helmet } from 'react-helmet';
88
import Footer from './Footer';
99
import useDarkMode from './useDarkMode';
1010
import BackToTopButton from './BackToTopButton';
11+
import categorizedMLContent from '../../categorizedMLContent';
12+
import categorizedDLContent from '../../categorizedDLContent';
13+
import categorizedGenAIContent from '../../categorizedGenAIContent';
14+
import categorizedPrerequisiteContent from '../../categorizedPrerequisiteContent';
1115

1216
// Animation variants
1317
const cardVariants = {
@@ -41,35 +45,39 @@ const LearnerDashboard = () => {
4145
setTimeout(() => setIsTransitioning(false), 300);
4246
};
4347

44-
// Roadmaps configuration with localStorage keys
48+
// Roadmaps configuration with localStorage keys and content
4549
const roadmaps = [
4650
{
4751
id: 'prerequisiteRoadmapProgress',
4852
title: 'Prerequisites',
4953
path: '/prerequisites',
5054
color: 'from-emerald-500 to-teal-500',
51-
icon: <BookOpen className="w-5 h-5" />
55+
icon: <BookOpen className="w-5 h-5" />,
56+
content: categorizedPrerequisiteContent
5257
},
5358
{
5459
id: 'mlRoadmapProgress',
5560
title: 'Machine Learning',
5661
path: '/machinelearning',
5762
color: 'from-blue-500 to-indigo-500',
58-
icon: <Target className="w-5 h-5" />
63+
icon: <Target className="w-5 h-5" />,
64+
content: categorizedMLContent
5965
},
6066
{
6167
id: 'dlRoadmapProgress',
6268
title: 'Deep Learning',
6369
path: '/deeplearning',
6470
color: 'from-purple-500 to-pink-500',
65-
icon: <TrendingUp className="w-5 h-5" />
71+
icon: <TrendingUp className="w-5 h-5" />,
72+
content: categorizedDLContent
6673
},
6774
{
6875
id: 'genaiRoadmapProgress',
6976
title: 'Generative AI',
7077
path: '/genai',
7178
color: 'from-amber-500 to-orange-500',
72-
icon: <Award className="w-5 h-5" />
79+
icon: <Award className="w-5 h-5" />,
80+
content: categorizedGenAIContent
7381
}
7482
];
7583

@@ -81,16 +89,25 @@ const LearnerDashboard = () => {
8189
let completedVideos = 0;
8290

8391
roadmaps.forEach(roadmap => {
92+
// Calculate total resources from content
93+
const roadmapContent = roadmap.content;
94+
if (roadmapContent) {
95+
Object.keys(roadmapContent).forEach(topicName => {
96+
const videos = roadmapContent[topicName];
97+
totalVideos += videos.length;
98+
});
99+
}
100+
101+
// Load progress from localStorage
84102
const roadmapProgress = localStorage.getItem(roadmap.id);
85103
if (roadmapProgress) {
86104
try {
87105
const parsed = JSON.parse(roadmapProgress);
88106
savedProgress[roadmap.id] = parsed;
89107

90-
// Calculate stats - the progress object has keys like "TopicName_videoUrl"
108+
// Calculate completed count - the progress object has keys like "TopicName_videoUrl"
91109
// and values are boolean (true for completed)
92110
Object.keys(parsed).forEach(key => {
93-
totalVideos++;
94111
if (parsed[key] === true) {
95112
completedVideos++;
96113
}
@@ -115,10 +132,20 @@ const LearnerDashboard = () => {
115132

116133
// Calculate progress for each roadmap
117134
const getRoadmapProgress = (roadmapId) => {
135+
const roadmap = roadmaps.find(r => r.id === roadmapId);
118136
const roadmapData = progress[roadmapId] || {};
119-
const videos = Object.keys(roadmapData);
120-
const completed = videos.filter(v => roadmapData[v] === true).length;
121-
const total = videos.length;
137+
138+
// Calculate total resources from content
139+
let total = 0;
140+
if (roadmap && roadmap.content) {
141+
Object.keys(roadmap.content).forEach(topicName => {
142+
const videos = roadmap.content[topicName];
143+
total += videos.length;
144+
});
145+
}
146+
147+
// Count completed videos
148+
const completed = Object.keys(roadmapData).filter(v => roadmapData[v] === true).length;
122149
const percent = total > 0 ? Math.round((completed / total) * 100) : 0;
123150

124151
return { completed, inProgress: 0, total, percent };

0 commit comments

Comments
 (0)