Repository navigation
Expand file tree
/
Copy pathLesson6.jsx
More file actions
187 lines (168 loc) · 5.48 KB
/
Copy pathLesson6.jsx
File metadata and controls
187 lines (168 loc) · 5.48 KB
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
// Lesson 6: Price Elasticity of Demand - Main Page Component
import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import {
FaArrowLeft,
FaPercentage,
FaCalculator,
FaListUl,
FaLightbulb,
FaChartBar,
FaClipboardList,
FaChevronRight,
FaChevronLeft
} from 'react-icons/fa';
import {
Introduction,
ConceptAndMeasurement,
TypesOfElasticity,
FactorsAffecting,
Applications,
Quiz
} from './components';
import { lesson6Data } from '../data/lesson6Data';
import { logLessonProgress } from '../../../services/firebase';
import { useAuth } from '../../../context/AuthContext';
import MicroTopicsMenu from '../components/MicroTopicsMenu';
import '../css/lessons.css';
const sections = lesson6Data.sections;
function Lesson6() {
// Load active section from localStorage, default to 'introduction'
const [activeSection, setActiveSection] = useState(() => {
const saved = localStorage.getItem('lesson6-activeSection');
return saved || 'introduction';
});
const [startTime] = useState(() => Date.now());
const lessonId = 'micro11-6';
const { logActivity } = useAuth();
useEffect(() => {
if (logActivity) {
logActivity('lesson_visit', { lessonId, lessonName: 'Production Function', chapter: 'Chapter 6' });
}
}, [logActivity, lessonId]);
// Save active section to localStorage whenever it changes
useEffect(() => {
localStorage.setItem('lesson6-activeSection', activeSection);
}, [activeSection]);
// Track time spent on unmount only
useEffect(() => {
return () => {
const timeSpent = Math.round((Date.now() - startTime) / 1000 / 60);
if (timeSpent > 0) {
logLessonProgress(lessonId, timeSpent);
}
};
}, [startTime, lessonId]);
const currentIndex = sections.findIndex(s => s.id === activeSection);
const goToPrevious = () => {
if (currentIndex > 0) {
setActiveSection(sections[currentIndex - 1].id);
}
};
const goToNext = () => {
if (currentIndex < sections.length - 1) {
setActiveSection(sections[currentIndex + 1].id);
}
};
const handleSectionChange = (sectionId) => {
setActiveSection(sectionId);
};
const renderActiveSection = () => {
switch (activeSection) {
case 'introduction':
return <Introduction />;
case 'concept-measurement':
return <ConceptAndMeasurement />;
case 'types-elasticity':
return <TypesOfElasticity />;
case 'factors-affecting':
return <FactorsAffecting />;
case 'applications':
return <Applications />;
case 'quiz':
return <Quiz
mcqQuestions={lesson6Data.mcqQuestions}
tfQuestions={lesson6Data.tfQuestions}
quizId="lesson6"
/>;
default:
return <Introduction />;
}
};
return (
<div className="lesson-page">
{/* Floating Background Elements */}
<div className="floating-elements">
<div className="float-circle circle-1"></div>
<div className="float-circle circle-2"></div>
<div className="float-circle circle-3"></div>
<div className="grid-pattern"></div>
</div>
{/* Header */}
<header className="lesson-header">
<div className="header-container">
<Link to="/lessons" className="back-link">
<FaArrowLeft />
<span>Back to Lessons</span>
</Link>
<div className="lesson-info">
<div className="lesson-badge">
<span className="badge-icon">📊</span>
<span className="badge-tag">Microeconomics</span>
</div>
<h1 className="lesson-title">
<span className="title-line">Price Elasticity of</span>
<span className="title-gradient">Demand</span>
</h1>
<p className="lesson-meta">
Based on NCERT Grade 11 Microeconomics • {lesson6Data.mcqQuestions.length + lesson6Data.tfQuestions.length} Quiz Questions
</p>
</div>
</div>
</header>
{/* Navigation - Responsive Hybrid */}
<MicroTopicsMenu
sections={sections}
activeSection={activeSection}
onSectionChange={handleSectionChange}
/>
{/* Main Content */}
<main className="lesson-content">
<div className="content-container">
{renderActiveSection()}
</div>
</main>
{/* Footer Navigation */}
<footer className="lesson-footer">
<div className="footer-container">
<button
className={`footer-btn prev ${currentIndex === 0 ? 'disabled' : ''}`}
onClick={goToPrevious}
disabled={currentIndex === 0}
>
<FaChevronLeft />
<span>Previous</span>
</button>
<div className="progress-indicator">
{sections.map((section, index) => (
<span
key={section.id}
className={`progress-dot ${index === currentIndex ? 'active' : ''} ${index < currentIndex ? 'completed' : ''}`}
onClick={() => handleSectionChange(section.id)}
></span>
))}
</div>
<button
className={`footer-btn next ${currentIndex === sections.length - 1 ? 'disabled' : ''}`}
onClick={goToNext}
disabled={currentIndex === sections.length - 1}
>
<span>Next</span>
<FaChevronRight />
</button>
</div>
</footer>
</div>
);
}
export default Lesson6;