Skip to content

Commit ebbd622

Browse files
committed
doneeeee
1 parent bdc67a3 commit ebbd622

File tree

3 files changed

+62
-17
lines changed

3 files changed

+62
-17
lines changed

src/pages/Dashboard/Dashboard.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ const Dashboard = () => {
99
const [courses, setCourses] = useState([]);
1010
const [createCourseModal, setCreateCourseModal] = useState(false);
1111

12+
const userType = localStorage.getItem("userType");
13+
1214
const Logout = () => {
1315
localStorage.removeItem("authToken");
1416
history.push("/");
1517
};
1618

1719
const history = useHistory();
1820

21+
const handleCardClick = (c) => {
22+
console.log(c);
23+
history.push(`/course/${c._id}`);
24+
};
25+
1926
useEffect(async () => {
2027
axios
2128
.get("https://cod-ed.herokuapp.com/course/all", {
@@ -42,12 +49,14 @@ const Dashboard = () => {
4249
<img src="/assets/logo.svg" alt="" />
4350
</a>
4451
<span>
45-
<button
46-
className="create"
47-
onClick={() => setCreateCourseModal(true)}
48-
>
49-
Create Course
50-
</button>
52+
{userType !== "user" ? (
53+
<button
54+
className="create"
55+
onClick={() => setCreateCourseModal(true)}
56+
>
57+
Create Course
58+
</button>
59+
) : null}
5160
<TextField
5261
variant="outlined"
5362
className="text-field"
@@ -64,7 +73,11 @@ const Dashboard = () => {
6473
<div className="cards">
6574
{courses.map((c) => {
6675
return (
67-
<div className="card">
76+
<div
77+
className="card"
78+
style={{ cursor: "pointer" }}
79+
onClick={(e) => handleCardClick(c)}
80+
>
6881
<img
6982
src={c.img ? c.img : "/assets/logo.svg"}
7083
alt=""

src/pages/Lessons/Lessons.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const Lessons = () => {
1414
const [createLesson, setCreateLesson] = useState(false);
1515
const { id } = useParams();
1616

17+
const userType = localStorage.getItem("userType");
18+
1719
const history = useHistory();
1820

1921
const getCourse = async () => {
@@ -39,6 +41,18 @@ const Lessons = () => {
3941
};
4042

4143
const handleLessonClick = (id, lesson) => {
44+
console.log(lesson);
45+
if (userType === "user") {
46+
history.push({
47+
pathname: `/student/editor/`,
48+
state: {
49+
details: lesson,
50+
},
51+
});
52+
53+
return;
54+
}
55+
4256
history.push({
4357
pathname: `/editor/${id}`,
4458
state: {
@@ -108,12 +122,14 @@ const Lessons = () => {
108122
<Container>
109123
<hr class="hr-text" data-content="LESSONS" />
110124
<div className="lesson-action-bar">
111-
<button
112-
className="create-lesson"
113-
onClick={() => setCreateLesson(true)}
114-
>
115-
Create Lesson
116-
</button>
125+
{userType !== "user" ? (
126+
<button
127+
className="create-lesson"
128+
onClick={() => setCreateLesson(true)}
129+
>
130+
Create Lesson
131+
</button>
132+
) : null}
117133
</div>
118134
<List style={{ marginTop: "30px" }}>
119135
{lessons.map((lesson) => (

src/pages/StudentEditor/StudentEditor.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ import { Link } from "react-router-dom";
1414
import CodeResult from "../../components/CodeResult/CodeResult";
1515
import { languageMap, monacoMap } from "../../utils/languages";
1616
import { getOutput, getToken } from "../../utils/codeRunning";
17+
import { motion } from "framer-motion";
1718

18-
const StudentEditor = () => {
19+
const StudentEditor = (props) => {
20+
const lesson = props.location.state.details;
1921
const [srcDoc, setSrcDoc] = useState("");
2022
const [code, setCode] = useState("");
21-
const [stream, setStream] = useState([]);
23+
const [stream, setStream] = useState(lesson.events);
2224
const [isPlaying, setIsPlaying] = useState(false);
2325
const [lastPaused, setLastPaused] = useState(0);
2426
const [output, setOutput] = useState("");
2527

26-
const [languageId, setLanguageId] = useState(54);
27-
const [language, setLanguage] = useState(languageMap[languageId]);
28+
const [languageId, setLanguageId] = useState(lesson.language);
29+
const [language, setLanguage] = useState(languageMap[lesson.language]);
2830
const [codeLoading, setCodeLoading] = useState(false);
2931

32+
const videoRef = useRef();
33+
3034
// const {
3135
// status,
3236
// startRecording,
@@ -63,6 +67,8 @@ const StudentEditor = () => {
6367
window.clearTimeout(id);
6468
});
6569

70+
videoRef.current.pause();
71+
6672
// let index = stream.length - timeouts.length;
6773
// console.log(index, stream.length, timeouts.length);
6874
// setLastPaused(index);
@@ -89,6 +95,8 @@ const StudentEditor = () => {
8995

9096
setTimeoutIds((prevState) => [...prevState, id]);
9197
}
98+
99+
videoRef.current.play();
92100
};
93101

94102
const handleChange = (e) => {
@@ -147,6 +155,14 @@ const StudentEditor = () => {
147155
onChange={handleChange}
148156
ref={inputRef}
149157
/>
158+
<motion.div className="video-div" drag dragMomentum={0}>
159+
<video
160+
src={lesson.video}
161+
width="200px"
162+
height="150px"
163+
ref={videoRef}
164+
/>
165+
</motion.div>
150166
</Grid>
151167

152168
<Grid item md={1} className="middle-row">

0 commit comments

Comments
 (0)