Skip to content

Commit 44e48d3

Browse files
authored
Merge pull request #15 from zachspang/dashboard
[Feature] Navigation from content back to course
2 parents 59be002 + 9dfe75b commit 44e48d3

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

frontend/src/components/pages/Content.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { useParams } from 'react-router-dom';
33

44
export function Content() {
5-
const { courseID } = useParams();
6-
const { contentID } = useParams();
5+
const { courseID } = useParams();
6+
const { contentID } = useParams();
7+
const [courseInfo, setCourseInfo] = useState(null);
8+
const [error, setError] = useState(null);
9+
10+
useEffect(() => {
11+
fetch(`http://localhost:4000/course/${courseID}`)
12+
.then((response) => {
13+
if (!response.ok) {
14+
throw new Error('Network response was not ok');
15+
}
16+
return response.json();
17+
})
18+
.then((data) => setCourseInfo(data.course))
19+
.catch((error) => setError(error.message));
20+
}, [courseID]);
21+
22+
if (error) return <p>Error: {error}</p>;
23+
if (!courseInfo) return <p>Loading...</p>;
724

825
return (
926
<div className="p-6">
10-
<h1 className="text-2xl font-bold mb-4">Course Name</h1>
27+
<a href={`/courses/${courseID}`}>
28+
<span className="text-2xl font-bold mb-4 hover:underline ">{courseInfo.title}</span>
29+
</a>
1130
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
1231
Course id: {courseID}
1332
</div>

0 commit comments

Comments
 (0)