Fix chaching bug for submissions
This commit is contained in:
parent
f1c27cf0e4
commit
e8d7402349
|
|
@ -269,6 +269,7 @@ onResult(async () => {
|
|||
assignment.value = {
|
||||
...loadedAssignment,
|
||||
};
|
||||
// Bugfix: this nextTick is needed. Without it the submissions are not diplayed when loading the module page.
|
||||
await nextTick();
|
||||
|
||||
assignment.value.submission = Object.assign(initialSubmission, assignment.value.submission);
|
||||
|
|
@ -341,7 +342,7 @@ const reopen = () => {
|
|||
},
|
||||
});
|
||||
};
|
||||
const _save = debounce(function (submission) {
|
||||
const _save = debounce(function () {
|
||||
saving.value++;
|
||||
const variables = {
|
||||
input: {
|
||||
|
|
@ -354,36 +355,13 @@ const _save = debounce(function (submission) {
|
|||
};
|
||||
doUpdateAssignmentWithSuccess(variables, {
|
||||
update(
|
||||
cache,
|
||||
_cache,
|
||||
{
|
||||
data: {
|
||||
updateAssignment: { successful, updatedAssignment },
|
||||
updateAssignment: { _successful, _updatedAssignment },
|
||||
},
|
||||
}
|
||||
) {
|
||||
try {
|
||||
if (successful) {
|
||||
const id = cache.identify({
|
||||
id: updatedAssignment.id,
|
||||
__typename: updatedAssignment.__typename,
|
||||
});
|
||||
const fragment = assignmentFragment;
|
||||
const fragmentName = 'AssignmentParts';
|
||||
cache.writeFragment({
|
||||
fragment,
|
||||
fragmentName,
|
||||
id,
|
||||
data: {
|
||||
...updatedAssignment,
|
||||
submission,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing
|
||||
}
|
||||
},
|
||||
) {},
|
||||
}).then(() => {
|
||||
saving.value--;
|
||||
if (saving.value === 0) {
|
||||
|
|
@ -396,9 +374,9 @@ const saveInput = (answer: string) => {
|
|||
corrections.value = '';
|
||||
unsaved.value = true;
|
||||
/*
|
||||
We update the assignment on this component, so the changes are reflected on it. The server does not return
|
||||
the updated entity, to prevent the UI to update when the user is entering his input
|
||||
*/
|
||||
We update the assignment on this component, so the changes are reflected on it. The server does not return
|
||||
the updated entity, to prevent the UI to update when the user is entering his input
|
||||
*/
|
||||
assignment.value.submission.text = answer;
|
||||
_save(assignment.value.submission);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue