Skip to content

Commit

Permalink
useMemo bad, reworked the student and admin fetchers
Browse files Browse the repository at this point in the history
  • Loading branch information
JibrilExe committed May 12, 2024
1 parent 50cfcd5 commit e47ebc7
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions frontend/src/components/Courses/CourseDetailTeacher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Tooltip,
Typography,
} from "@mui/material";
import { ChangeEvent, useCallback, useEffect, useMemo, useState } from "react";
import { ChangeEvent, useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import {
Course,
Expand Down Expand Up @@ -142,27 +142,37 @@ export function CourseDetailTeacher(): JSX.Element {
const lang = i18n.language;
const navigate = useNavigate();

useMemo(() => {
setAdminObjects([]);
const admins_and_teacher = admins.concat({uid: course.teacher});
admins_and_teacher.forEach((admin) => {
getUser(admin.uid).then((user: Me) => {
setAdminObjects((prev) => {
return [...prev, user];
});
});
});
useEffect(() => {
const fetchAdminData = async () => {
setAdminObjects([]);
const admins_and_teacher = admins.concat({ uid: course.teacher });
const adminObjects: Me[] = [];

for (const admin of admins_and_teacher) {
const user = await getUser(admin.uid);
adminObjects.push(user);
}

setAdminObjects(adminObjects);
};

fetchAdminData();
}, [admins, course]);

useMemo(() => {
setStudentObjects([]);
students.forEach((student) => {
getUser(student.uid).then((user: Me) => {
setStudentObjects((prev) => {
return [...prev, user];
});
});
});
useEffect(() => {
const fetchStudentData = async () => {
setStudentObjects([]);
const studentObjects: Me[] = [];

for (const student of students) {
const user = await getUser(student.uid);
studentObjects.push(user);
}

setStudentObjects(studentObjects);
};

fetchStudentData();
}, [students]);

const handleCheckboxChange = (
Expand Down

0 comments on commit e47ebc7

Please sign in to comment.