diff --git a/frontend/frontend/src/components/CourseCard.tsx b/frontend/frontend/src/components/CourseCard.tsx index 42a11c06..c59b055b 100644 --- a/frontend/frontend/src/components/CourseCard.tsx +++ b/frontend/frontend/src/components/CourseCard.tsx @@ -97,10 +97,14 @@ export function CourseCard({ setGroups(groups) const submissionPromises = groups.map(async (group) => { - const response = await instance.get( + const response = await instance.get( `/indieningen/?project=${group.project}&groep=${group.groep_id}` ) - return response.data + return response.data.sort( + (a: Submission, b: Submission) => { + return dayjs(b.tijdstip).diff(dayjs(a.tijdstip)) + } + )[0] }) const submissions = await axios.all(submissionPromises) @@ -155,13 +159,14 @@ export function CourseCard({ } const mySubmission = submissions.find( - (submission) => submission.groep === myGroup.groep_id + (submission) => + (submission ? submission.groep : 0) === myGroup.groep_id ) if (!mySubmission) { return SubmissionStatus.FAIL } - + console.log('myStatus', mySubmission.status) return mySubmission.status } diff --git a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx index f3f748f5..00b5c997 100644 --- a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx +++ b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx @@ -59,10 +59,13 @@ export function SubmissionListItemTeacherPage({ const submissionsResponse = await instance.get( `/indieningen/?groep=${group_id}` ) - const lastSubmission = - submissionsResponse.data[ - submissionsResponse.data.length - 1 - ] + const lastSubmission = submissionsResponse.data.sort( + (a: Submission, b: Submission) => { + return dayjs(a.tijdstip).isBefore(dayjs(b.tijdstip)) + ? -1 + : 1 + } + )[submissionsResponse.data.length - 1] if (lastSubmission) { const lastSubmissionResponse = await instance.get( `indieningen/${lastSubmission.indiening_id}/` @@ -77,7 +80,7 @@ export function SubmissionListItemTeacherPage({ ) newSubmission.bestand = await instance .get( - `/indieningen/${lastSubmission.indiening_id}/indiening_bestand`, + `/indieningen/${lastSubmission.indiening_id}/indiening_bestand/`, { responseType: 'blob', } @@ -175,12 +178,14 @@ export function SubmissionListItemTeacherPage({ + ) : submitted.status > 0 ? ( + ) : ( - submitted !== undefined && ( - - ) + )} , diff --git a/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx b/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx index 84711667..1e848a98 100644 --- a/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx +++ b/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx @@ -1,11 +1,12 @@ import { Box, + CircularProgress, + Dialog, ListItem, ListItemText, + Skeleton, Stack, Typography, - Dialog, - CircularProgress, } from '@mui/material' import List from '@mui/material/List' import { useEffect, useState } from 'react' @@ -57,7 +58,7 @@ function joinLeaveButton( ) } - if (disabled){ + if (disabled) { return ( <> {t('group_full')} @@ -87,90 +88,51 @@ export function ChooseGroup() { const [userLoading, setUserLoading] = useState(true) const assignmentId = params.assignmentId + const courseid = params.courseId const handleClose = () => { setOpen(false) } useEffect(() => { - setUserLoading(true) - setLoading(true) - instance - .get('/gebruikers/me/') - .then((res) => { - setUser(res.data) - }) - .catch((err) => { - console.log(err) - }) - setUserLoading(false) - instance - .get('/projecten/' + assignmentId + '/') - .then((res) => { - setAssignment(res.data) - }) - .catch((err) => { - console.log(err) - }) - instance - .get('projecten/' + assignmentId) - .then((res) => { - instance - .get('vakken/' + res.data.vak) - .then((res) => { - //setStudenten(res.data.studenten) - for (let i = 0; i < res.data.studenten.length; i++) { - const studentid = res.data.studenten[i] - instance - .get('gebruikers/' + studentid) - .then((res) => { - setStudenten((oldstudenten) => { - return { - ...oldstudenten, - [res.data.user]: res.data, - } - }) - }) - .catch((err) => { - console.log(err) - }) - } - }) - .catch((err) => { - console.log(err) - }) - }) - .catch((err) => { - console.log(err) - }) + async function fetchData() { + setLoading(true) + setUserLoading(true) + try { + const user = await instance.get('/gebruikers/me/') + setUser(user.data) + setUserLoading(false) - instance - .get('groepen/?project=' + assignmentId) - .then((res) => { - for (let i = 0; i < res.data.length; i++) { - setGroups((oldGroups) => { - let found = false - const id = res.data[i].groep_id - for (const group of oldGroups) { - if (group.groep_id == id) { - found = true - } - } - if (found) { - return oldGroups - } else { - return [...oldGroups, res.data[i]].sort((a, b) => { - return a.groep_id - b.groep_id - }) + const assignment = await instance.get( + '/projecten/' + assignmentId + '/' + ) + setAssignment(assignment.data) + + const course = await instance.get('vakken/' + courseid) + for (let i = 0; i < course.data.studenten.length; i++) { + const studentid = course.data.studenten[i] + const student = await instance.get( + 'gebruikers/' + studentid + ) + setStudenten((oldstudenten) => { + return { + ...oldstudenten, + [student.data.user]: student.data, } }) } - }) - .catch((err) => { - console.log(err) - }) - setLoading(false) - }, []) + const groups = await instance.get( + 'groepen/?project=' + assignmentId + ) + setGroups(groups.data) + } catch (err) { + console.error(err) + } finally { + setLoading(false) + } + } + fetchData().catch((err) => console.error(err)) + }, [assignmentId, courseid]) return ( <> @@ -253,436 +215,471 @@ export function ChooseGroup() { }, }} > - {groups.map((group: Group) => { - //const group=getGroup(id) + {loading ? ( + [...Array(3)].map(() => ( + + )) + ) : ( + <> + {groups.map( + (group: Group) => { + //const group=getGroup(id) - const handleJoin = () => { - setGroups( - ( - oldGroups - ): Group[] => { - if ( - user == - undefined - ) { - return oldGroups - } - if ( - assignment == - undefined - ) { - return oldGroups - } + const handleJoin = + () => { + setGroups( + ( + oldGroups + ): Group[] => { + if ( + user == + undefined + ) { + return oldGroups + } + if ( + assignment == + undefined + ) { + return oldGroups + } - let j = 0 + let j = 0 - let edittedgroup = - undefined + let edittedgroup = + undefined - for ( - let i = 0; - i < - oldGroups.length; - i++ - ) { - if ( - oldGroups[ - i - ].studenten.includes( - user.user - ) - ) { - const newgroup1 = - { - groep_id: - oldGroups[ - i - ] - .groep_id, - project: - oldGroups[ - i - ] - .project, - studenten: - oldGroups[ - i - ].studenten.filter( - ( - student - ) => - student != + for ( + let i = 0; + i < + oldGroups.length; + i++ + ) { + if ( + oldGroups[ + i + ].studenten.includes( user.user - ), - } + ) + ) { + const newgroup1 = + { + groep_id: + oldGroups[ + i + ] + .groep_id, + project: + oldGroups[ + i + ] + .project, + studenten: + oldGroups[ + i + ].studenten.filter( + ( + student + ) => + student != + user.user + ), + } - instance - .patch( - 'groepen/' + - oldGroups[ - i - ] - .groep_id + - '/', - { - studenten: - oldGroups[ + instance + .patch( + 'groepen/' + + oldGroups[ + i + ] + .groep_id + + '/', + { + studenten: + oldGroups[ + i + ].studenten.filter( + ( + student + ) => + student != + user.user + ), + } + ) + .catch( + ( + err + ) => { + console.log( + err + ) + } + ) + j = i - ].studenten.filter( - ( - student - ) => - student != - user.user - ), - } - ) - .catch( - ( - err - ) => { - console.log( - err - ) + edittedgroup = + newgroup1 + } } - ) - j = i - edittedgroup = - newgroup1 - } - } - for ( - let i = 0; - i < - oldGroups.length; - i++ - ) { - if ( - oldGroups[i] - .groep_id == - group.groep_id - ) { - if ( - group - .studenten - .length >= - assignment.max_groep_grootte - ) { - return oldGroups - } - const newgroup = - { - groep_id: - group.groep_id, - project: - group.project, - studenten: - [ - ...group.studenten, - user.user, - ], - } - instance - .patch( - 'groepen/' + - group.groep_id + - '/', - { - studenten: - [ - ...group.studenten, - user.user, - ], - } - ) - .catch( - ( - err - ) => { - console.log( - err - ) - } - ) + for ( + let i = 0; + i < + oldGroups.length; + i++ + ) { + if ( + oldGroups[ + i + ] + .groep_id == + group.groep_id + ) { + if ( + group + .studenten + .length >= + assignment.max_groep_grootte + ) { + return oldGroups + } + const newgroup = + { + groep_id: + group.groep_id, + project: + group.project, + studenten: + [ + ...group.studenten, + user.user, + ], + } + instance + .patch( + 'groepen/' + + group.groep_id + + '/', + { + studenten: + [ + ...group.studenten, + user.user, + ], + } + ) + .catch( + ( + err + ) => { + console.log( + err + ) + } + ) - if ( - edittedgroup != - undefined - ) { - if ( - i < - j - ) { - return [ - ...oldGroups.slice( - 0, - i - ), - newgroup, - ...oldGroups.slice( - i + - 1, - j - ), - edittedgroup, - ...oldGroups.slice( - j + - 1 - ), - ].sort( - ( - a, - b - ) => { - return ( - a.groep_id - - b.groep_id + if ( + edittedgroup != + undefined + ) { + if ( + i < + j + ) { + return [ + ...oldGroups.slice( + 0, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1, + j + ), + edittedgroup, + ...oldGroups.slice( + j + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } + ) + } + return [ + ...oldGroups.slice( + 0, + j + ), + edittedgroup, + ...oldGroups.slice( + j + + 1, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } + ) + } + + return [ + ...oldGroups.slice( + 0, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } ) } - ) - } - return [ - ...oldGroups.slice( - 0, - j - ), - edittedgroup, - ...oldGroups.slice( - j + - 1, - i - ), - newgroup, - ...oldGroups.slice( - i + - 1 - ), - ].sort( - ( - a, - b - ) => { - return ( - a.groep_id - - b.groep_id - ) } - ) - } - - return [ - ...oldGroups.slice( - 0, - i - ), - newgroup, - ...oldGroups.slice( - i + - 1 - ), - ].sort( - ( - a, - b - ) => { - return ( - a.groep_id - - b.groep_id - ) + return oldGroups } ) } - } - return oldGroups - } - ) - } - const handleLeave = () => { - setGroups((oldGroups) => { - if (user == undefined) { - return oldGroups - } - for ( - let i = 0; - i < - oldGroups.length; - i++ - ) { - if ( - oldGroups[i] - .groep_id == - group.groep_id - ) { - const newgroup = - { - groep_id: - group.groep_id, - project: - group.project, - studenten: - group.studenten.filter( - ( - student - ) => - student != - user.user - ), - } - instance - .patch( - 'groepen/' + - group.groep_id + - '/', - { - studenten: - group.studenten.filter( - ( - student - ) => - student != - user.user - ), - } - ) - .catch( + const handleLeave = + () => { + setGroups( ( - err + oldGroups ) => { - console.log( - err - ) + if ( + user == + undefined + ) { + return oldGroups + } + for ( + let i = 0; + i < + oldGroups.length; + i++ + ) { + if ( + oldGroups[ + i + ] + .groep_id == + group.groep_id + ) { + const newgroup = + { + groep_id: + group.groep_id, + project: + group.project, + studenten: + group.studenten.filter( + ( + student + ) => + student != + user.user + ), + } + instance + .patch( + 'groepen/' + + group.groep_id + + '/', + { + studenten: + group.studenten.filter( + ( + student + ) => + student != + user.user + ), + } + ) + .catch( + ( + err + ) => { + console.log( + err + ) + } + ) + + return [ + ...oldGroups.slice( + 0, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } + ) + } + } + return oldGroups } ) + } - return [ - ...oldGroups.slice( - 0, - i - ), - newgroup, - ...oldGroups.slice( - i + 1 - ), - ].sort( - (a, b) => { - return ( - a.groep_id - - b.groep_id - ) - } - ) - } - } - return oldGroups - }) - } - - return ( - <> - - - , - + + - {loading ? ( - - {t( - 'members_loading' - )} - - ) : ( - <> - {group - .studenten - .length > - 0 ? ( - group.studenten.map( - ( - studentid - ) => { - const student = - studenten[ - studentid - ] - if ( - student - ) { - console.log( - 'Student:', - student - ) - return ( - , + + {loading ? ( + + {t( + 'members_loading' + )} + + ) : ( + <> + {group + .studenten + .length > + 0 ? ( + group.studenten.map( + ( + studentid + ) => { + const student = + studenten[ + studentid + ] + if ( + student + ) { + console.log( + 'Student:', + student + ) + return ( + + {student.first_name + + ' ' + + student.last_name} + + ) } - > - {student.first_name + - ' ' + - student.last_name} - + return null + } ) - } - return null - } - ) - ) : ( - - {t( - 'no_members_yet' - )} - - )} - - )} - , - <> - {joinLeaveButton( - user != - undefined - ? group.studenten.includes( - user.user - ) - : false, - group.studenten.length === assignment?.max_groep_grootte - && !(user != - undefined - ? group.studenten.includes( - user.user - ) - : false), - handleJoin, - handleLeave - )} - , - ]} - /> - - - ) - })} + ) : ( + + {t( + 'no_members_yet' + )} + + )} + + )} + , + <> + {joinLeaveButton( + user != + undefined + ? group.studenten.includes( + user.user + ) + : false, + group + .studenten + .length === + assignment?.max_groep_grootte && + !(user != + undefined + ? group.studenten.includes( + user.user + ) + : false), + handleJoin, + handleLeave + )} + , + ]} + /> + + + ) + } + )} + + )} { - setAvailableStudents(() => - Array.from(studentNames.keys()).filter( - (student) => - !newGroups.some((group) => - group.studenten.includes(student) - ) - ) + const filteredStudents = Array.from(studentNames.keys()).filter( + (student) => + !newGroups.some((group) => group.studenten.includes(student)) ) - setFilteredStudents(availableStudents) + + setAvailableStudents(filteredStudents) + setFilteredStudents(filteredStudents) }, [newGroups, studentNames]) //Handle current group change diff --git a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx index 3255e349..920a9ceb 100644 --- a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx +++ b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx @@ -135,20 +135,20 @@ export function SubmissionPage() { //Get the submission file const newSubmission: Submission = submissionResponse.data - if (newSubmission.result !== 'No tests: OK') { + if ( + newSubmission.status !== SubmissionStatus.PENDING && + newSubmission.result !== 'No tests: OK' + ) { const regex = /Testing (.*)$/ const matches = newSubmission.result.match(regex) if (matches !== null) { - matches.map((match) => { - match.replace(':', '\n') - return match - }) + newSubmission.result = matches[0] } } newSubmission.filename = submissionResponse.data.bestand.replace(/^.*[\\/]/, '') newSubmission.bestand = await instance - .get(`/indieningen/${submissionId}/indiening_bestand`, { + .get(`/indieningen/${submissionId}/indiening_bestand/`, { responseType: 'blob', }) .then((res) => { @@ -225,9 +225,11 @@ export function SubmissionPage() { } // Fetch students - fetchStudents().catch((error) => - console.error('Error fetching students data:', error) - ) + if (submission) { + fetchStudents().catch((error) => + console.error('Error fetching students data:', error) + ) + } }, [submission]) if (fetchError) {