Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30cd1bf

Browse files
Fixed lessons access
1 parent 2c42b7a commit 30cd1bf

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/lesson.jsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import './css/index.css';
22
import { useState, lazy, Suspense, useEffect } from 'react';
3+
import { useParams } from "react-router-dom";
34
import { FaArrowLeft, FaArrowRight, FaHome, FaBars } from "react-icons/fa";
45
import "./css/lessonMenu.css";
5-
import hljs from "highlight.js";
6-
import "highlight.js/styles/monokai.css";
6+
import hljs from "highlight.js";
7+
import "highlight.js/styles/monokai.css";
78

89
const theme = localStorage.getItem("theme");
910
switch(theme) {
@@ -53,10 +54,10 @@ const lessons = [
5354
{id: 0, title: "Data types", content: () => {
5455
const Comp = lazy(() => import("./lessons/Lesson5.jsx"));
5556
return <Comp/>;
56-
}},
57-
{id: 1, title: "Variables", content: () => {
58-
const Comp = lazy(() => import("./lessons/Lesson6.jsx"));
59-
return <Comp/>;
57+
}},
58+
{id: 1, title: "Variables", content: () => {
59+
const Comp = lazy(() => import("./lessons/Lesson6.jsx"));
60+
return <Comp/>;
6061
}}
6162
] // Unit 1
6263
]
@@ -90,7 +91,7 @@ function NavBar(props) {
9091
if (props.unit - 1 < 0) {
9192
console.log("This is the first lesson. Cannot go to the previous lesson.");
9293
return "";
93-
}
94+
}
9495
let unitId = props.unit;
9596
if (lessons[--unitId]) {
9697
previousInfo = {unit: unitId, lesson: lessons[unitId].length - 1};
@@ -169,19 +170,20 @@ function SideBar(props) {
169170
)
170171
}
171172

172-
function LessonMenu({ match: { params }}) {
173+
function LessonMenu(props) {
174+
let params = useParams();
173175
let [unit, setUnit] = useState(params.unit);
174176
let [id, setId] = useState(params.id);
175-
let [sideBarShouldAppear, setSideBarShouldAppear] = useState(false);
176-
177-
function LoadingText() {
178-
useEffect(() => {
179-
return () => {
180-
hljs.highlightAll();
181-
}
182-
}, []);
183-
184-
return <main><h1>Loading lesson...</h1></main>;
177+
let [sideBarShouldAppear, setSideBarShouldAppear] = useState(false);
178+
179+
function LoadingText() {
180+
useEffect(() => {
181+
return () => {
182+
hljs.highlightAll();
183+
}
184+
}, []);
185+
186+
return <main><h1>Loading lesson...</h1></main>;
185187
}
186188

187189
function getLessonContent() {

0 commit comments

Comments
 (0)