Skip to content
Snippets Groups Projects
Commit c492cab2 authored by permcu's avatar permcu
Browse files

Implement cache update

This overwrites the handleUpdateAfterCreateOrPatch method of the
createOrPatchMixin and adapts it to work with documentations that
where send by the backend as either already created or dummy.
parent 9e566fe4
No related branches found
No related tags found
2 merge requests!352Draft: Resolve "Add dialog with each lesson's students",!350Resolve "Add simple course book list"
......@@ -5,6 +5,7 @@
:gql-additional-query-args="gqlQueryArgs"
:enable-create="false"
:enable-edit="false"
@lastQuery="lastQuery = $event"
>
<template #default="{ items }">
<v-list-item v-for="day in groupDocsByDay(items)" two-line>
......@@ -12,7 +13,7 @@
<v-list-item-title>{{ $d(day[0], "short") }}</v-list-item-title>
<v-list>
<v-list-item v-for="doc in day.slice(1)">
<documentation-modal :documentation="doc" />
<documentation-modal :documentation="doc" :affected-query="lastQuery" />
</v-list-item>
</v-list>
</v-list-item-content>
......@@ -61,6 +62,7 @@ export default {
data() {
return {
gqlQuery: documentationsForCoursebook,
lastQuery: null,
};
},
computed: {
......
......@@ -55,7 +55,6 @@
<script>
import createOrPatchMixin from "aleksis.core/mixins/createOrPatchMixin.js";
// TODO: Update createOrPatchMixin to handle createOrPatch update of cache
export default {
name: "LessonSummary",
......@@ -85,6 +84,18 @@ export default {
(str.length > 25) ? str.slice(0, 24) + '' : str
: "";
},
handleUpdateAfterCreateOrPatch(itemId, wasCreate) {
return (cached, incoming) => {
for (const object of incoming) {
console.log('summary: handleUpdateAfterCreateOrPatch', object);
// Replace the current documentation
const index = cached.findIndex((o) => o[itemId] === this.documentation.id);
// merged with the incoming partial documentation
cached[index] = {...this.documentation, ...object};
}
return cached;
};
},
save() {
if (this.topic || this.homework || this.groupNote) {
const topic = this.topic ? { topic: this.topic } : {};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment