Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opnieuw performance omhoog gedaan #282

Merged
merged 1 commit into from
May 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions frontend/frontend/src/pages/groupsPage/GroupsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { Add } from '@mui/icons-material'
import ClearIcon from '@mui/icons-material/Clear'
import SaveIcon from '@mui/icons-material/Save'
import WarningPopup from '../../components/WarningPopup.tsx'
import axios, { AxiosResponse } from 'axios'
import { User } from '../subjectsPage/AddChangeSubjectPage.tsx'

// group interface
export interface Group {
Expand Down Expand Up @@ -182,39 +184,22 @@ export function GroupsPage() {
await instance
.get('/vakken/' + courseId)
.then(async (response) => {
// This function fetches the names of the students in parallel
const newStudentNames = new Map<number, string>()

for (const student of response.data.studenten) {
await instance
.get('/gebruikers/' + student)
.then((response) => {
newStudentNames.set(
student,
response.data.first_name +
' ' +
response.data.last_name
)
})
.catch((error) => {
console.log(error)
})
}
for (const student of response.data.studenten) {
await instance
.get('/gebruikers/' + student)
.then((response) => {
newStudentNames.set(
student,
response.data.first_name +
' ' +
response.data.last_name
)
console.log(
'available names:' +
Array.from(newStudentNames.entries())
)
})
}
const studentPromises: Promise<AxiosResponse<User>>[] =
response.data.studenten.map((id: number) =>
instance.get('/gebruikers/' + id)
)
const studentResponses = await axios.all(studentPromises)

studentResponses.forEach((response) => {
const student: User = response.data
newStudentNames.set(
student.user,
student.first_name + ' ' + student.last_name
)
})

setStudentNames(() => newStudentNames)
})
Expand Down Expand Up @@ -275,7 +260,7 @@ export function GroupsPage() {
.catch((error) => {
console.log(error)
})
}, [assignmentId, courseId, newGroupSize, studentNames.size])
}, [assignmentId, courseId])

useEffect(() => {
setAvailableStudents(() =>
Expand Down