diff --git a/src/components/coursemanage/files/files.tsx b/src/components/coursemanage/files/files.tsx index bfcd93e..d7bab59 100644 --- a/src/components/coursemanage/files/files.tsx +++ b/src/components/coursemanage/files/files.tsx @@ -262,7 +262,7 @@ export const Files = (props: IFilesProps) => { commitMessage, selectedFiles ); - queryClient.invalidateQueries({ queryKey: ['assignments', props.lecture.id] }); + await queryClient.invalidateQueries({ queryKey: ['assignments'] }); enqueueSnackbar('Successfully Pushed Assignment', { variant: 'success' }); diff --git a/src/components/coursemanage/grading/manual-grading.tsx b/src/components/coursemanage/grading/manual-grading.tsx index d46f322..c1c5d2f 100644 --- a/src/components/coursemanage/grading/manual-grading.tsx +++ b/src/components/coursemanage/grading/manual-grading.tsx @@ -207,8 +207,8 @@ export const ManualGrading = () => { enqueueSnackbar('Generating feedback for submission!', { variant: 'success' }); - queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent']}); - reload(); + await queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent']}); + await reload(); } catch (err) { console.error(err); enqueueSnackbar('Error Generating Feedback', { diff --git a/src/components/coursemanage/grading/table-toolbar.tsx b/src/components/coursemanage/grading/table-toolbar.tsx index f225c03..7f67e65 100644 --- a/src/components/coursemanage/grading/table-toolbar.tsx +++ b/src/components/coursemanage/grading/table-toolbar.tsx @@ -116,14 +116,14 @@ export function EnhancedTableToolbar(props: EnhancedTableToolbarProps) { .then(response => { enqueueSnackbar( 'Successfully matched ' + - response.syncable_users + - ' submissions with learning platform', + response.syncable_users + + ' submissions with learning platform', { variant: 'success' } ); enqueueSnackbar( 'Successfully synced latest submissions with feedback of ' + - response.synced_user + - ' users', + response.synced_user + + ' users', { variant: 'success' } ); }) @@ -187,7 +187,9 @@ export function EnhancedTableToolbar(props: EnhancedTableToolbarProps) { enqueueSnackbar(`Generating feedback for ${numSelected} submissions!`, { variant: 'success' }); - queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent']}); + await queryClient.invalidateQueries({ + queryKey: ['submissionsAssignmentStudent'] + }); } catch (err) { console.error(err); enqueueSnackbar('Error Generating Feedback', { @@ -302,7 +304,8 @@ export function EnhancedTableToolbar(props: EnhancedTableToolbarProps) { diff --git a/src/components/coursemanage/lecture.tsx b/src/components/coursemanage/lecture.tsx index b6a01d3..1fb8ed1 100644 --- a/src/components/coursemanage/lecture.tsx +++ b/src/components/coursemanage/lecture.tsx @@ -18,16 +18,15 @@ import { import * as React from 'react'; import { Assignment } from '../../model/assignment'; import { Lecture } from '../../model/lecture'; -import { deleteAssignment, getAllAssignments } from '../../services/assignments.service'; +import { + deleteAssignment, + getAllAssignments +} from '../../services/assignments.service'; import { CreateDialog, EditLectureDialog } from '../util/dialog'; import { getLecture, updateLecture } from '../../services/lectures.service'; import { red, grey } from '@mui/material/colors'; import { enqueueSnackbar } from 'notistack'; -import { - useNavigate, - useNavigation, - useRouteLoaderData -} from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import { ButtonTr, GraderTable } from '../util/table'; import { DeadlineComponent } from '../util/deadline'; import CloseIcon from '@mui/icons-material/Close'; @@ -163,10 +162,14 @@ export const LectureComponent = () => { enabled: !!lectureId }); - const { data: assignments = [], isLoading: isLoadingAssignments, refetch: refetchAssignments } = useQuery({ + const { + data: assignments = [], + isLoading: isLoadingAssignments, + refetch: refetchAssignments + } = useQuery({ queryKey: ['assignments', lecture, lectureId], queryFn: () => getAllAssignments(lectureId), - enabled: !!lecture + enabled: !!lecture }); React.useEffect(() => { @@ -175,12 +178,10 @@ export const LectureComponent = () => { } }, [assignments]); - const [lectureState, setLecture] = React.useState(lecture); const [assignmentsState, setAssignments] = React.useState([]); const [isEditDialogOpen, setEditDialogOpen] = React.useState(false); - if (isLoadingLecture || isLoadingAssignments) { return (
@@ -195,19 +196,20 @@ export const LectureComponent = () => { setEditDialogOpen(true); }; - - const handleUpdateLecture = (updatedLecture) => { + const handleUpdateLecture = updatedLecture => { updateLecture(updatedLecture).then( - async (response) => { + async response => { await updateMenus(true); setLecture(response); // Invalidate query key "lectures" and "completedLectures", so that we trigger refetch on lectures table and correct lecture name is shown in the table! - queryClient.invalidateQueries({ queryKey: ['lectures'] }); - queryClient.invalidateQueries({ queryKey: ['completedLectures'] }); + await queryClient.invalidateQueries({ queryKey: ['lectures'] }); + await queryClient.invalidateQueries({ + queryKey: ['completedLectures'] + }); }, - (error) => { + error => { enqueueSnackbar(error.message, { - variant: 'error', + variant: 'error' }); } ); @@ -236,11 +238,7 @@ export const LectureComponent = () => { alignItems="center" sx={{ mt: 2, mb: 1 }} > - + {lecture.code === lecture.name ? ( The name of the lecture is identical to the lecture code. You diff --git a/src/components/coursemanage/overview/assignment-status.tsx b/src/components/coursemanage/overview/assignment-status.tsx index ad1d835..647550e 100644 --- a/src/components/coursemanage/overview/assignment-status.tsx +++ b/src/components/coursemanage/overview/assignment-status.tsx @@ -99,7 +99,7 @@ export const AssignmentStatus = (props: IAssignmentStatusProps) => { try { await updateStatusMutation.mutateAsync(status); await refetchAssignment(); - queryClient.invalidateQueries({ queryKey: ['assignments', props.lecture.id] }); + await queryClient.invalidateQueries({ queryKey: ['assignments'] }); enqueueSnackbar(success, { variant: 'success' }); } catch (err) { enqueueSnackbar(error, { variant: 'error' }); diff --git a/src/components/coursemanage/settings/settings.tsx b/src/components/coursemanage/settings/settings.tsx index 0ca3f1a..288f3e3 100644 --- a/src/components/coursemanage/settings/settings.tsx +++ b/src/components/coursemanage/settings/settings.tsx @@ -41,6 +41,7 @@ import { updateMenus } from '../../../menu'; import { extractIdsFromBreadcrumbs } from '../../util/breadcrumbs'; import { getLecture } from '../../../services/lectures.service'; import { useQuery } from '@tanstack/react-query'; +import { queryClient } from '../../../widgets/assignmentmanage'; const gradingBehaviourHelp = `Specifies the behaviour when a students submits an assignment.\n No Automatic Grading: No action is taken on submit.\n @@ -70,14 +71,14 @@ export const SettingsComponent = () => { const { data: lecture } = useQuery({ queryKey: ['lecture', lectureId], - queryFn: () => getLecture(lectureId), - enabled: !!lectureId, + queryFn: () => getLecture(lectureId), + enabled: !!lectureId }); const { data: assignment } = useQuery({ queryKey: ['assignment', assignmentId], - queryFn: () => getAssignment(lectureId, assignmentId), - enabled: !!lecture && !!assignmentId, + queryFn: () => getAssignment(lectureId, assignmentId), + enabled: !!lecture && !!assignmentId }); const [checked, setChecked] = React.useState(assignment.due_date !== null); @@ -146,7 +147,7 @@ export const SettingsComponent = () => { } } } - if (nErrors == 0) { + if (nErrors === 0) { // error object has to be empty, otherwise submit is blocked return {}; } @@ -173,6 +174,7 @@ export const SettingsComponent = () => { updateAssignment(lecture.id, updatedAssignment).then( async response => { await updateMenus(true); + await queryClient.invalidateQueries({ queryKey: ['assignments'] }); enqueueSnackbar('Successfully Updated Assignment', { variant: 'success' }); diff --git a/src/components/util/dialog.tsx b/src/components/util/dialog.tsx index 83adba3..45c83d1 100644 --- a/src/components/util/dialog.tsx +++ b/src/components/util/dialog.tsx @@ -282,6 +282,7 @@ export const CreateDialog = (props: ICreateDialogProps) => { async a => { await updateMenus(true); props.handleSubmit(a); + await queryClient.invalidateQueries({ queryKey: ['assignments'] }); }, error => { @@ -290,7 +291,6 @@ export const CreateDialog = (props: ICreateDialogProps) => { }); } ); - queryClient.invalidateQueries({ queryKey: ['assignments', props.lecture.id] }); setOpen(false); } });