Skip to content

Commit

Permalink
opnieuw performance omhoog gedaan
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendemeurichy committed May 19, 2024
1 parent 9dedf3b commit b65475e
Showing 1 changed file with 17 additions and 32 deletions.
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

0 comments on commit b65475e

Please sign in to comment.