From c492cab2a5ca7334083e76141e28eb2840dd07f6 Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Fri, 9 Feb 2024 14:28:25 +0100 Subject: [PATCH] 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. --- .../apps/alsijil/frontend/components/Coursebook.vue | 4 +++- .../components/documentation/LessonSummary.vue | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/Coursebook.vue index 0d27a6e38..348f1c726 100644 --- a/aleksis/apps/alsijil/frontend/components/Coursebook.vue +++ b/aleksis/apps/alsijil/frontend/components/Coursebook.vue @@ -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: { diff --git a/aleksis/apps/alsijil/frontend/components/documentation/LessonSummary.vue b/aleksis/apps/alsijil/frontend/components/documentation/LessonSummary.vue index 2d0599841..8396743b3 100644 --- a/aleksis/apps/alsijil/frontend/components/documentation/LessonSummary.vue +++ b/aleksis/apps/alsijil/frontend/components/documentation/LessonSummary.vue @@ -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 } : {}; -- GitLab