diff --git a/frontend/frontend/src/Theme.ts b/frontend/frontend/src/Theme.ts index 5fd57018..b2a6b70b 100644 --- a/frontend/frontend/src/Theme.ts +++ b/frontend/frontend/src/Theme.ts @@ -26,6 +26,9 @@ const theme = createTheme({ success: { main: '#81A476', }, + warning: { + main: '#FFC107', + }, info: { main: '#47464A', }, diff --git a/frontend/frontend/src/components/AssignmentListItem.tsx b/frontend/frontend/src/components/AssignmentListItem.tsx index c68a54a1..18157710 100644 --- a/frontend/frontend/src/components/AssignmentListItem.tsx +++ b/frontend/frontend/src/components/AssignmentListItem.tsx @@ -7,15 +7,17 @@ import { } from '@mui/material' import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline' import HighlightOffIcon from '@mui/icons-material/HighlightOff' +import AccessAlarmIcon from '@mui/icons-material/AccessAlarm' import { useNavigate } from 'react-router-dom' import { t } from 'i18next' +import { SubmissionStatus } from '../pages/submissionPage/SubmissionPage.tsx' interface AssignmentListItemProps { id: string courseId: string projectName: string dueDate?: string - status: boolean + status: SubmissionStatus isStudent: boolean } @@ -84,16 +86,21 @@ export function AssignmentListItem({ {/* Status Icon (for students only) */} {isStudent && ( - {status ? ( + {status === SubmissionStatus.PASSED ? ( - ) : ( + ) : status === SubmissionStatus.FAIL ? ( + ) : ( + )} )} diff --git a/frontend/frontend/src/components/CourseCard.tsx b/frontend/frontend/src/components/CourseCard.tsx index b0d35006..42a11c06 100644 --- a/frontend/frontend/src/components/CourseCard.tsx +++ b/frontend/frontend/src/components/CourseCard.tsx @@ -19,7 +19,10 @@ import { Course, project } from '../pages/mainPage/MainPage.tsx' import dayjs from 'dayjs' import { CourseCardSkeleton } from './CourseCardSkeleton.tsx' -import { Submission } from '../pages/submissionPage/SubmissionPage.tsx' +import { + Submission, + SubmissionStatus, +} from '../pages/submissionPage/SubmissionPage.tsx' import { Group } from '../pages/groupsPage/GroupsPage.tsx' import axios from 'axios' /* @@ -60,9 +63,8 @@ export function CourseCard({ gearchiveerd: false, }) const [assignments, setAssignments] = useState([]) - const [groupsWithSubmissions, setGroupsWithSubmissions] = useState( - [] - ) + const [submissions, setSubmissions] = useState([]) + const [groups, setGroups] = useState([]) const [teachers, setTeachers] = useState< { first_name: string; last_name: string }[] >([]) @@ -91,25 +93,18 @@ export function CourseCard({ const groups: Group[] = await instance .get(`/groepen/?student=${userid}`) .then((response) => response.data) + + setGroups(groups) + const submissionPromises = groups.map(async (group) => { const response = await instance.get( - `/indieningen/?project=${group.project}` + `/indieningen/?project=${group.project}&groep=${group.groep_id}` ) return response.data }) const submissions = await axios.all(submissionPromises) - console.log(groups) - const validGroups = groups.filter((group) => - submissions - .flat(Infinity) - .some( - (submission) => - submission.groep === group.groep_id - ) - ) - - setGroupsWithSubmissions(validGroups) + setSubmissions(submissions) } if (courseResponse.data && courseResponse.data.lesgevers) { @@ -150,6 +145,26 @@ export function CourseCard({ pinEvent() } + function getmyStatus(assignment: project) { + const myGroup = groups.find( + (group) => group.project === assignment.project_id + ) + + if (!myGroup) { + return SubmissionStatus.FAIL + } + + const mySubmission = submissions.find( + (submission) => submission.groep === myGroup.groep_id + ) + + if (!mySubmission) { + return SubmissionStatus.FAIL + } + + return mySubmission.status + } + return ( <> {loading ? ( @@ -407,10 +422,8 @@ export function CourseCard({ ) : undefined } - status={groupsWithSubmissions.some( - (group) => - group.project === - assignment.project_id + status={getmyStatus( + assignment )} isStudent={isStudent} /> @@ -455,12 +468,8 @@ export function CourseCard({ : undefined } status={ - groupsWithSubmissions.some( - ( - group - ) => - group.project === - assignment.project_id + getmyStatus( + assignment ) //TODO: status has to check if there is already a submission } @@ -503,10 +512,8 @@ export function CourseCard({ ) || undefined } - status={groupsWithSubmissions.some( - (group) => - group.project === - assignment.project_id + status={getmyStatus( + assignment )} isStudent={ isStudent diff --git a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx index d33821f2..3255e349 100644 --- a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx +++ b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx @@ -29,7 +29,7 @@ import { User } from '../subjectsPage/AddChangeSubjectPage.tsx' */ // Define an enum for submission status -enum SubmissionStatus { +export enum SubmissionStatus { FAIL = -1, PENDING = 0, PASSED = 1,