Handle cache in student submission without mutating it
This commit is contained in:
parent
a85296a628
commit
3e518e21c0
|
|
@ -6,7 +6,7 @@ export default {
|
||||||
intro: 'intro',
|
intro: 'intro',
|
||||||
assignments: {},
|
assignments: {},
|
||||||
objectiveGroups: [],
|
objectiveGroups: [],
|
||||||
id: '',
|
id: 'TW9kdWxlTm9kZToxMjM=',
|
||||||
chapters: [],
|
chapters: [],
|
||||||
topic: {
|
topic: {
|
||||||
title: 'A Topic Mock Title',
|
title: 'A Topic Mock Title',
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ describe('Snapshot', () => {
|
||||||
success: true,
|
success: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
UpdateLastModule: {},
|
||||||
ModuleSnapshotsQuery: {
|
ModuleSnapshotsQuery: {
|
||||||
module: {
|
module: {
|
||||||
...module,
|
...module,
|
||||||
|
|
|
||||||
|
|
@ -218,27 +218,32 @@
|
||||||
const variables = {
|
const variables = {
|
||||||
id: this.studentSubmission.id,
|
id: this.studentSubmission.id,
|
||||||
};
|
};
|
||||||
const data = store.readQuery({query, variables});
|
const { studentSubmission } = store.readQuery({query, variables});
|
||||||
|
|
||||||
if (data) {
|
if (studentSubmission) {
|
||||||
if (!data.studentSubmission.submissionFeedback) {
|
let text;
|
||||||
data.studentSubmission.submissionFeedback = {
|
|
||||||
'__typename': 'SubmissionFeedbackNode',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
data.studentSubmission.submissionFeedback = Object.assign({}, data.studentSubmission.submissionFeedback, {
|
|
||||||
id: updatedSubmissionFeedback.id,
|
|
||||||
final: updatedSubmissionFeedback.final,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (updatedSubmissionFeedback.text !== undefined) {
|
if (updatedSubmissionFeedback.text !== undefined) {
|
||||||
// text is only being set on create and on turning in, then we'll update the cache with it. Otherwise, we'll trust the local state, as to not overwrite the input field
|
// text is only being set on create and on turning in, then we'll update the cache with it. Otherwise, we'll trust the local state, as to not overwrite the input field
|
||||||
data.studentSubmission.submissionFeedback.text = updatedSubmissionFeedback.text;
|
text = updatedSubmissionFeedback.text;
|
||||||
} else {
|
} else {
|
||||||
data.studentSubmission.submissionFeedback.text = this.studentSubmission.submissionFeedback ? this.studentSubmission.submissionFeedback.text : '';
|
text = this.studentSubmission.submissionFeedback ? this.studentSubmission.submissionFeedback.text : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const submissionFeedback = Object.assign({}, studentSubmission.submissionFeedback, {
|
||||||
|
id: updatedSubmissionFeedback.id,
|
||||||
|
final: updatedSubmissionFeedback.final,
|
||||||
|
'__typename': 'SubmissionFeedbackNode',
|
||||||
|
text
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
studentSubmission: {
|
||||||
|
...studentSubmission,
|
||||||
|
submissionFeedback
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
store.writeQuery({query, variables, data});
|
store.writeQuery({query, variables, data});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue