From 6d1eb48fe53ecfd81b83bfdba683b5df38ddb132 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Wed, 2 Feb 2022 16:53:23 +0100 Subject: [PATCH] Fix delete mutation update --- client/src/components/ContentBlock.vue | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/client/src/components/ContentBlock.vue b/client/src/components/ContentBlock.vue index 0c08ac42..15b7975c 100644 --- a/client/src/components/ContentBlock.vue +++ b/client/src/components/ContentBlock.vue @@ -84,6 +84,7 @@ import {hidden} from '@/helpers/visibility'; import {CONTENT_TYPE} from '@/consts/types'; import PopoverLink from '@/components/ui/PopoverLink'; + import {removeAtIndex} from '@/graphql/immutable-operations'; const ContentComponent = () => import(/* webpackChunkName: "content-components" */'@/components/content-blocks/ContentComponent'); const instruments = { @@ -101,8 +102,8 @@ default: () => ({}) }, parent: { - type: String, - default: '' + type: Object, + default: () => ({}) }, editMode: { type: Boolean, @@ -219,19 +220,22 @@ } }, update(store, {data: {deleteContentBlock: {success}}}) { - try { if (success) { const query = CHAPTER_QUERY; const variables = { - id: parent + id: parent.id + }; + const {chapter} = store.readQuery({query, variables}); + const index = chapter.contentBlocks.findIndex(contentBlock => contentBlock.id === id); + const contentBlocks = removeAtIndex(chapter.contentBlocks, index); + const data = { + chapter: { + ...chapter, + contentBlocks + } }; - const data = store.readQuery({query, variables}); - data.chapter.contentBlocks.splice(data.chapter.contentBlocks.findIndex(contentBlock => contentBlock.id === id), 1); store.writeQuery({query, variables, data}); } - } catch (e) { - // Query did not exist in the cache, and apollo throws a generic Error. Do nothing - } } }); },