From febd820267ff5a9c1cd7a48d220ef9c88685ed51 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Nov 2021 10:20:25 +0100 Subject: [PATCH] Fix broken bookmark creation --- .../update-content-bookmark-mutation.js | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/client/src/helpers/update-content-bookmark-mutation.js b/client/src/helpers/update-content-bookmark-mutation.js index cedf0214..674e449c 100644 --- a/client/src/helpers/update-content-bookmark-mutation.js +++ b/client/src/helpers/update-content-bookmark-mutation.js @@ -7,57 +7,8 @@ const compareUuid = uuid => element => element.uuid === uuid; export const constructContentComponentBookmarkMutation = (uuid, bookmarked, parent, root) => { let mutation = {}; - - if (parent.__typename === 'ContentBlockNode') { - mutation = { - mutation: UPDATE_CONTENT_BOOKMARK, - variables: { - input: { - uuid, - contentBlock: root, - bookmarked - } - }, - update: (store, response) => { - const query = CONTENT_BLOCK_QUERY; - const variables = {id: root}; - const data = store.readQuery({ - query, - variables - }); - - const bookmarks = data.contentBlock.bookmarks; - - if (bookmarked) { - bookmarks.push({ - note: null, - uuid, - __typename: 'ContentBlockBookmarkNode' - }); - } else { - let index = bookmarks.findIndex(compareUuid(uuid)); - if (index > -1) { - bookmarks.splice(index, 1); - } - } - - data.contentBlock.bookmarks = bookmarks; - - store.writeQuery({ - data, - query, - variables - }); - }, - optimisticResponse: { - __typename: 'Mutation', - updateContentBookmark: { - __typename: 'UpdateContentBookmarkPayload', - success: true - } - } - }; - } else { + + if (parent.__typename === 'InstrumentNode') { mutation = { mutation: UPDATE_INSTRUMENT_BOOKMARK, variables: { @@ -106,6 +57,55 @@ export const constructContentComponentBookmarkMutation = (uuid, bookmarked, pare } } }; + } else { + mutation = { + mutation: UPDATE_CONTENT_BOOKMARK, + variables: { + input: { + uuid, + contentBlock: root, + bookmarked + } + }, + update: (store, response) => { + const query = CONTENT_BLOCK_QUERY; + const variables = {id: root}; + const data = store.readQuery({ + query, + variables + }); + + const bookmarks = data.contentBlock.bookmarks; + + if (bookmarked) { + bookmarks.push({ + note: null, + uuid, + __typename: 'ContentBlockBookmarkNode' + }); + } else { + let index = bookmarks.findIndex(compareUuid(uuid)); + if (index > -1) { + bookmarks.splice(index, 1); + } + } + + data.contentBlock.bookmarks = bookmarks; + + store.writeQuery({ + data, + query, + variables + }); + }, + optimisticResponse: { + __typename: 'Mutation', + updateContentBookmark: { + __typename: 'UpdateContentBookmarkPayload', + success: true + } + } + }; } return mutation; };