Skip to content

Commit 7ee3d03

Browse files
committed
fix: Updating assignment properties in settings, didn't invalidate assignments queries, fixed that. Added "await" to all query invalidations.
1 parent d0f7972 commit 7ee3d03

File tree

7 files changed

+41
-38
lines changed

7 files changed

+41
-38
lines changed

src/components/coursemanage/files/files.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export const Files = (props: IFilesProps) => {
262262
commitMessage,
263263
selectedFiles
264264
);
265-
queryClient.invalidateQueries({ queryKey: ['assignments', props.lecture.id] });
265+
await queryClient.invalidateQueries({ queryKey: ['assignments'] });
266266
enqueueSnackbar('Successfully Pushed Assignment', {
267267
variant: 'success'
268268
});

src/components/coursemanage/grading/manual-grading.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ export const ManualGrading = () => {
207207
enqueueSnackbar('Generating feedback for submission!', {
208208
variant: 'success'
209209
});
210-
queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent']});
211-
reload();
210+
await queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent']});
211+
await reload();
212212
} catch (err) {
213213
console.error(err);
214214
enqueueSnackbar('Error Generating Feedback', {

src/components/coursemanage/grading/table-toolbar.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ export function EnhancedTableToolbar(props: EnhancedTableToolbarProps) {
116116
.then(response => {
117117
enqueueSnackbar(
118118
'Successfully matched ' +
119-
response.syncable_users +
120-
' submissions with learning platform',
119+
response.syncable_users +
120+
' submissions with learning platform',
121121
{ variant: 'success' }
122122
);
123123
enqueueSnackbar(
124124
'Successfully synced latest submissions with feedback of ' +
125-
response.synced_user +
126-
' users',
125+
response.synced_user +
126+
' users',
127127
{ variant: 'success' }
128128
);
129129
})
@@ -187,7 +187,9 @@ export function EnhancedTableToolbar(props: EnhancedTableToolbarProps) {
187187
enqueueSnackbar(`Generating feedback for ${numSelected} submissions!`, {
188188
variant: 'success'
189189
});
190-
queryClient.invalidateQueries({ queryKey: ['submissionsAssignmentStudent']});
190+
await queryClient.invalidateQueries({
191+
queryKey: ['submissionsAssignmentStudent']
192+
});
191193
} catch (err) {
192194
console.error(err);
193195
enqueueSnackbar('Error Generating Feedback', {
@@ -302,7 +304,8 @@ export function EnhancedTableToolbar(props: EnhancedTableToolbarProps) {
302304
</Tooltip>
303305
<Tooltip
304306
title={
305-
checkAutogradeStatus() ? 'Generate feedback for all selected submissions'
307+
checkAutogradeStatus()
308+
? 'Generate feedback for all selected submissions'
306309
: 'All selected submissions have to be automatically graded!'
307310
}
308311
>

src/components/coursemanage/lecture.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ import {
1818
import * as React from 'react';
1919
import { Assignment } from '../../model/assignment';
2020
import { Lecture } from '../../model/lecture';
21-
import { deleteAssignment, getAllAssignments } from '../../services/assignments.service';
21+
import {
22+
deleteAssignment,
23+
getAllAssignments
24+
} from '../../services/assignments.service';
2225
import { CreateDialog, EditLectureDialog } from '../util/dialog';
2326
import { getLecture, updateLecture } from '../../services/lectures.service';
2427
import { red, grey } from '@mui/material/colors';
2528
import { enqueueSnackbar } from 'notistack';
26-
import {
27-
useNavigate,
28-
useNavigation,
29-
useRouteLoaderData
30-
} from 'react-router-dom';
29+
import { useNavigate } from 'react-router-dom';
3130
import { ButtonTr, GraderTable } from '../util/table';
3231
import { DeadlineComponent } from '../util/deadline';
3332
import CloseIcon from '@mui/icons-material/Close';
@@ -163,10 +162,14 @@ export const LectureComponent = () => {
163162
enabled: !!lectureId
164163
});
165164

166-
const { data: assignments = [], isLoading: isLoadingAssignments, refetch: refetchAssignments } = useQuery<AssignmentDetail[]>({
165+
const {
166+
data: assignments = [],
167+
isLoading: isLoadingAssignments,
168+
refetch: refetchAssignments
169+
} = useQuery<AssignmentDetail[]>({
167170
queryKey: ['assignments', lecture, lectureId],
168171
queryFn: () => getAllAssignments(lectureId),
169-
enabled: !!lecture
172+
enabled: !!lecture
170173
});
171174

172175
React.useEffect(() => {
@@ -175,12 +178,10 @@ export const LectureComponent = () => {
175178
}
176179
}, [assignments]);
177180

178-
179181
const [lectureState, setLecture] = React.useState(lecture);
180182
const [assignmentsState, setAssignments] = React.useState<Assignment[]>([]);
181183
const [isEditDialogOpen, setEditDialogOpen] = React.useState(false);
182184

183-
184185
if (isLoadingLecture || isLoadingAssignments) {
185186
return (
186187
<div>
@@ -195,19 +196,20 @@ export const LectureComponent = () => {
195196
setEditDialogOpen(true);
196197
};
197198

198-
199-
const handleUpdateLecture = (updatedLecture) => {
199+
const handleUpdateLecture = updatedLecture => {
200200
updateLecture(updatedLecture).then(
201-
async (response) => {
201+
async response => {
202202
await updateMenus(true);
203203
setLecture(response);
204204
// Invalidate query key "lectures" and "completedLectures", so that we trigger refetch on lectures table and correct lecture name is shown in the table!
205-
queryClient.invalidateQueries({ queryKey: ['lectures'] });
206-
queryClient.invalidateQueries({ queryKey: ['completedLectures'] });
205+
await queryClient.invalidateQueries({ queryKey: ['lectures'] });
206+
await queryClient.invalidateQueries({
207+
queryKey: ['completedLectures']
208+
});
207209
},
208-
(error) => {
210+
error => {
209211
enqueueSnackbar(error.message, {
210-
variant: 'error',
212+
variant: 'error'
211213
});
212214
}
213215
);
@@ -236,11 +238,7 @@ export const LectureComponent = () => {
236238
alignItems="center"
237239
sx={{ mt: 2, mb: 1 }}
238240
>
239-
<Stack
240-
direction="row"
241-
alignItems="center"
242-
sx={{ mr: 2}}
243-
>
241+
<Stack direction="row" alignItems="center" sx={{ mr: 2 }}>
244242
{lecture.code === lecture.name ? (
245243
<Alert severity="info">
246244
The name of the lecture is identical to the lecture code. You

src/components/coursemanage/overview/assignment-status.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const AssignmentStatus = (props: IAssignmentStatusProps) => {
9999
try {
100100
await updateStatusMutation.mutateAsync(status);
101101
await refetchAssignment();
102-
queryClient.invalidateQueries({ queryKey: ['assignments', props.lecture.id] });
102+
await queryClient.invalidateQueries({ queryKey: ['assignments'] });
103103
enqueueSnackbar(success, { variant: 'success' });
104104
} catch (err) {
105105
enqueueSnackbar(error, { variant: 'error' });

src/components/coursemanage/settings/settings.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { updateMenus } from '../../../menu';
4141
import { extractIdsFromBreadcrumbs } from '../../util/breadcrumbs';
4242
import { getLecture } from '../../../services/lectures.service';
4343
import { useQuery } from '@tanstack/react-query';
44+
import { queryClient } from '../../../widgets/assignmentmanage';
4445

4546
const gradingBehaviourHelp = `Specifies the behaviour when a students submits an assignment.\n
4647
No Automatic Grading: No action is taken on submit.\n
@@ -70,14 +71,14 @@ export const SettingsComponent = () => {
7071

7172
const { data: lecture } = useQuery<Lecture>({
7273
queryKey: ['lecture', lectureId],
73-
queryFn: () => getLecture(lectureId),
74-
enabled: !!lectureId,
74+
queryFn: () => getLecture(lectureId),
75+
enabled: !!lectureId
7576
});
7677

7778
const { data: assignment } = useQuery<Assignment>({
7879
queryKey: ['assignment', assignmentId],
79-
queryFn: () => getAssignment(lectureId, assignmentId),
80-
enabled: !!lecture && !!assignmentId,
80+
queryFn: () => getAssignment(lectureId, assignmentId),
81+
enabled: !!lecture && !!assignmentId
8182
});
8283

8384
const [checked, setChecked] = React.useState(assignment.due_date !== null);
@@ -146,7 +147,7 @@ export const SettingsComponent = () => {
146147
}
147148
}
148149
}
149-
if (nErrors == 0) {
150+
if (nErrors === 0) {
150151
// error object has to be empty, otherwise submit is blocked
151152
return {};
152153
}
@@ -173,6 +174,7 @@ export const SettingsComponent = () => {
173174
updateAssignment(lecture.id, updatedAssignment).then(
174175
async response => {
175176
await updateMenus(true);
177+
await queryClient.invalidateQueries({ queryKey: ['assignments'] });
176178
enqueueSnackbar('Successfully Updated Assignment', {
177179
variant: 'success'
178180
});

src/components/util/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export const CreateDialog = (props: ICreateDialogProps) => {
282282
async a => {
283283
await updateMenus(true);
284284
props.handleSubmit(a);
285+
await queryClient.invalidateQueries({ queryKey: ['assignments'] });
285286
},
286287

287288
error => {
@@ -290,7 +291,6 @@ export const CreateDialog = (props: ICreateDialogProps) => {
290291
});
291292
}
292293
);
293-
queryClient.invalidateQueries({ queryKey: ['assignments', props.lecture.id] });
294294
setOpen(false);
295295
}
296296
});

0 commit comments

Comments
 (0)