From e8d7402349626b310a893f08cc267c6f8ee6736c Mon Sep 17 00:00:00 2001 From: Lorenz Padberg Date: Wed, 27 Mar 2024 12:47:17 +0100 Subject: [PATCH] Fix chaching bug for submissions --- .../content-blocks/assignment/Assignment.vue | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/client/src/components/content-blocks/assignment/Assignment.vue b/client/src/components/content-blocks/assignment/Assignment.vue index d60bcdcf..2586bd12 100644 --- a/client/src/components/content-blocks/assignment/Assignment.vue +++ b/client/src/components/content-blocks/assignment/Assignment.vue @@ -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);