Skip to content

Commit

Permalink
Merge pull request #311 from SELab-2/mainpage_clock
Browse files Browse the repository at this point in the history
fix clock when pending mainpage
  • Loading branch information
Bendemeurichy authored May 22, 2024
2 parents 89650ea + 79a8fbd commit 60e933c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
3 changes: 3 additions & 0 deletions frontend/frontend/src/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const theme = createTheme({
success: {
main: '#81A476',
},
warning: {
main: '#FFC107',
},
info: {
main: '#47464A',
},
Expand Down
13 changes: 10 additions & 3 deletions frontend/frontend/src/components/AssignmentListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -84,16 +86,21 @@ export function AssignmentListItem({
{/* Status Icon (for students only) */}
{isStudent && (
<ListItemIcon sx={{ minWidth: 35 }}>
{status ? (
{status === SubmissionStatus.PASSED ? (
<CheckCircleOutlineIcon
id="check"
sx={{ color: 'success.main' }}
/>
) : (
) : status === SubmissionStatus.FAIL ? (
<HighlightOffIcon
id="cross"
sx={{ color: 'error.main' }}
/>
) : (
<AccessAlarmIcon
id="clock"
sx={{ color: 'warning.main' }}
/>
)}
</ListItemIcon>
)}
Expand Down
67 changes: 37 additions & 30 deletions frontend/frontend/src/components/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
/*
Expand Down Expand Up @@ -60,9 +63,8 @@ export function CourseCard({
gearchiveerd: false,
})
const [assignments, setAssignments] = useState<project[]>([])
const [groupsWithSubmissions, setGroupsWithSubmissions] = useState<Group[]>(
[]
)
const [submissions, setSubmissions] = useState<Submission[]>([])
const [groups, setGroups] = useState<Group[]>([])
const [teachers, setTeachers] = useState<
{ first_name: string; last_name: string }[]
>([])
Expand Down Expand Up @@ -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<Submission>(
`/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) {
Expand Down Expand Up @@ -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 ? (
Expand Down Expand Up @@ -407,10 +422,8 @@ export function CourseCard({
)
: undefined
}
status={groupsWithSubmissions.some(
(group) =>
group.project ===
assignment.project_id
status={getmyStatus(
assignment
)}
isStudent={isStudent}
/>
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -503,10 +512,8 @@ export function CourseCard({
) ||
undefined
}
status={groupsWithSubmissions.some(
(group) =>
group.project ===
assignment.project_id
status={getmyStatus(
assignment
)}
isStudent={
isStudent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 60e933c

Please sign in to comment.