Skip to content

Commit fbe5910

Browse files
committed
Combine dashboard useEffects
1 parent 24189a1 commit fbe5910

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

frontend/src/components/pages/CourseDashboard.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export function CourseDashboard() {
5757
return;
5858
}
5959

60-
fetch(`http://localhost:4000/courses/${userId}`)
60+
async function fetchCourses() {
61+
await fetch(`http://localhost:4000/courses/${userId}`)
6162
.then((response) => {
6263
if (!response.ok) {
6364
throw new Error('Network response was not ok');
@@ -66,17 +67,10 @@ export function CourseDashboard() {
6667
})
6768
.then((data) => setCourseInfo(data.courses))
6869
.catch((error) => setError(error.message));
69-
}, []);
70-
71-
useEffect(() => {
72-
const userId = Cookies.get('userId');
73-
74-
if (!userId) {
75-
setError('User ID not found');
76-
return;
7770
}
7871

79-
fetch(`http://localhost:4000/user/${userId}`)
72+
async function fetchUser() {
73+
await fetch(`http://localhost:4000/user/${userId}`)
8074
.then((response) => {
8175
if (!response.ok) {
8276
throw new Error('Network response was not ok');
@@ -85,11 +79,15 @@ export function CourseDashboard() {
8579
})
8680
.then((data) => setUserInfo(data.user))
8781
.catch((error) => setError(error.message));
82+
}
83+
84+
fetchCourses();
85+
fetchUser();
8886
}, []);
8987

9088
if (error) return <p>Error: {error}</p>;
9189
if (!courseInfo || !userInfo) return <p>Loading...</p>;
92-
90+
9391
let createButton = null;
9492
if (userInfo.role === "educator"){
9593
createButton = <Modal

0 commit comments

Comments
 (0)