From e92412cf21d6e77336d9a799d8009af235f02986 Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 16 Jan 2020 14:10:16 +0100 Subject: [PATCH] Clean up code --- client/src/helpers/new-note-mutation.js | 9 +++------ client/src/helpers/update-content-bookmark-mutation.js | 10 ++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/client/src/helpers/new-note-mutation.js b/client/src/helpers/new-note-mutation.js index 83843423..399e1cec 100644 --- a/client/src/helpers/new-note-mutation.js +++ b/client/src/helpers/new-note-mutation.js @@ -5,6 +5,7 @@ import MODULE_QUERY from '@/graphql/gql/moduleByIdQuery.gql'; import INSTRUMENT_FRAGMENT from '@/graphql/gql/fragments/instrumentParts.gql'; const getBlockType = id => atob(id).split(':')[0]; +const compareUuid = note => element => element.uuid === note.content; export const constructNoteMutation = (n) => { let update = () => { @@ -22,9 +23,7 @@ export const constructNoteMutation = (n) => { const bookmarks = data.contentBlock.bookmarks; - let index = bookmarks.findIndex(element => { - return element.uuid === n.content; - }); + let index = bookmarks.findIndex(compareUuid(n)); if (index > -1) { let el = bookmarks[index]; @@ -49,9 +48,7 @@ export const constructNoteMutation = (n) => { const bookmarks = data.bookmarks; - let index = bookmarks.findIndex(element => { - return element.uuid === n.content; - }); + let index = bookmarks.findIndex(compareUuid(n)); if (index > -1) { let el = bookmarks[index]; diff --git a/client/src/helpers/update-content-bookmark-mutation.js b/client/src/helpers/update-content-bookmark-mutation.js index fbb76239..9a2253cd 100644 --- a/client/src/helpers/update-content-bookmark-mutation.js +++ b/client/src/helpers/update-content-bookmark-mutation.js @@ -3,6 +3,8 @@ import UPDATE_INSTRUMENT_BOOKMARK from '@/graphql/gql/mutations/updateInstrument import CONTENT_BLOCK_QUERY from '@/graphql/gql/contentBlockQuery.gql'; import INSTRUMENT_FRAGMENT from '@/graphql/gql/fragments/instrumentParts.gql'; +const compareUuid = uuid => element => element.uuid === uuid; + export const constructContentComponentBookmarkMutation = (uuid, bookmarked, parent, root) => { let mutation = {}; @@ -33,9 +35,7 @@ export const constructContentComponentBookmarkMutation = (uuid, bookmarked, pare __typename: 'ContentBlockBookmarkNode' }); } else { - let index = bookmarks.findIndex(element => { - return element.uuid === uuid; - }); + let index = bookmarks.findIndex(compareUuid(uuid)); if (index > -1) { bookmarks.splice(index, 1); } @@ -84,9 +84,7 @@ export const constructContentComponentBookmarkMutation = (uuid, bookmarked, pare __typename: 'InstrumentBookmarkNode' }) } else { - let index = bookmarks.findIndex(element => { - return element.uuid === uuid; - }); + let index = bookmarks.findIndex(compareUuid(uuid)); if (index > -1) { bookmarks.splice(index, 1); }