Fix continuous input bug

This commit is contained in:
Ramon Wenger 2018-12-04 13:24:36 +01:00
parent d46d0dde0a
commit 0080dfe0d7
2 changed files with 2506 additions and 2496 deletions

4978
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -58,7 +58,8 @@
</div> </div>
</template> </template>
<template v-if="!isStudent"> <template v-if="!isStudent">
<router-link class="button" :to="{name: 'submissions', params: { id: assignment.id }}">Zu den Ergebnissen</router-link> <router-link class="button" :to="{name: 'submissions', params: { id: assignment.id }}">Zu den Ergebnissen
</router-link>
</template> </template>
</div> </div>
</template> </template>
@ -99,7 +100,8 @@
}, },
methods: { methods: {
_save: debounce(function () { _save: debounce(function (submission) {
this.saving++;
this.$apollo.mutate({ this.$apollo.mutate({
mutation: UPDATE_ASSIGNMENT_MUTATION_WITH_SUCCESS, mutation: UPDATE_ASSIGNMENT_MUTATION_WITH_SUCCESS,
variables: { variables: {
@ -119,15 +121,22 @@
id: updatedAssignment.id id: updatedAssignment.id
}; };
const data = store.readQuery({query, variables}); const data = store.readQuery({query, variables});
data.assignment = Object.assign({}, updatedAssignment);
data.assignment = Object.assign({}, updatedAssignment, {
submission
});
store.writeQuery({query, variables, data}); store.writeQuery({query, variables, data});
} }
} catch (e) { } catch (e) {
console.error(e);
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing // Query did not exist in the cache, and apollo throws a generic Error. Do nothing
} }
} }
}).then(() => { }).then(() => {
this.unsaved = false; this.saving--;
if (this.saving === 0) {
this.unsaved = false;
}
}); });
}, 500), }, 500),
saveInput: function (answer) { saveInput: function (answer) {
@ -137,11 +146,11 @@
the updated entity, to prevent the UI to update when the user is entering his input the updated entity, to prevent the UI to update when the user is entering his input
*/ */
this.assignment.submission.text = answer; this.assignment.submission.text = answer;
this._save(); this._save(this.assignment.submission);
}, },
changeDocumentUrl(documentUrl) { changeDocumentUrl(documentUrl) {
this.assignment.submission.document = documentUrl; this.assignment.submission.document = documentUrl;
this._save(); this._save(this.assignment.submission);
}, },
turnIn() { turnIn() {
this.$apollo.mutate({ this.$apollo.mutate({
@ -194,7 +203,8 @@
permissions: [] permissions: []
}, },
inputType: 'text', inputType: 'text',
unsaved: false unsaved: false,
saving: 0
} }
}, },
} }