From 0ade5bdbf9e8ed71e9ad72e9a237f25e901a18e0 Mon Sep 17 00:00:00 2001 From: Marijana Petojevic Date: Mon, 28 Oct 2024 10:57:56 +0100 Subject: [PATCH] fix: Show correct active step status in assignment view when the page is loaded. --- src/components/assignment/assignment.tsx | 13 +++++++------ src/components/assignment/submission-list.tsx | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/assignment/assignment.tsx b/src/components/assignment/assignment.tsx index a388612..f1c15ad 100644 --- a/src/components/assignment/assignment.tsx +++ b/src/components/assignment/assignment.tsx @@ -121,7 +121,7 @@ export const AssignmentComponent = () => { } = useQuery({ queryKey: ['subLeft'], queryFn: async () => { - refetchSubmissions(); + await refetchSubmissions(); const response = await getSubmissionCount(lectureId, assignmentId); const remainingSubmissions = assignment.max_submissions - response.submission_count; @@ -154,7 +154,7 @@ export const AssignmentComponent = () => { setActiveStatus(active_step); }); } - }, [lecture, assignment]); + }, [lecture, assignment, submissions]); if ( isLoadingAssignment || @@ -190,7 +190,7 @@ export const AssignmentComponent = () => { enqueueSnackbar('Successfully Reset Assignment', { variant: 'success' }); - refetchFiles(); + await refetchFiles(); } catch (e) { if (e instanceof Error) { enqueueSnackbar('Error Reset Assignment: ' + e.message, { @@ -214,9 +214,10 @@ export const AssignmentComponent = () => { async () => { await submitAssignment(lecture, assignment, true).then( () => { - refetchSubleft(); - const active_step = calculateActiveStep(submissions); - setActiveStatus(active_step); + refetchSubleft().then(() => { + const active_step = calculateActiveStep(submissions); + setActiveStatus(active_step); + }); enqueueSnackbar('Successfully Submitted Assignment', { variant: 'success' }); diff --git a/src/components/assignment/submission-list.tsx b/src/components/assignment/submission-list.tsx index 6366762..f04d77c 100644 --- a/src/components/assignment/submission-list.tsx +++ b/src/components/assignment/submission-list.tsx @@ -131,7 +131,8 @@ export const SubmissionList = (props: ISubmissionListProps) => { startIcon={} size="small" onClick={() => { - const warningMessage = props.subLeft === 0 && props.submissions.length === 1 + const warningMessage = + props.subLeft === 0 && props.submissions.length === 1 ? 'This is your last submission left. If you delete it, you won’t be able to submit again and you will be graded with 0 points.' : ''; showDialog( @@ -146,10 +147,10 @@ export const SubmissionList = (props: ISubmissionListProps) => { props.assignment.id, value.id ); - queryClient.invalidateQueries({ + await queryClient.invalidateQueries({ queryKey: ['submissions'] }); - queryClient.invalidateQueries({ + await queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent'] }); enqueueSnackbar('Successfully Deleted Submission', {