Fix broken bookmark creation
This commit is contained in:
parent
591c922c98
commit
febd820267
|
|
@ -7,57 +7,8 @@ const compareUuid = uuid => element => element.uuid === uuid;
|
||||||
|
|
||||||
export const constructContentComponentBookmarkMutation = (uuid, bookmarked, parent, root) => {
|
export const constructContentComponentBookmarkMutation = (uuid, bookmarked, parent, root) => {
|
||||||
let mutation = {};
|
let mutation = {};
|
||||||
|
|
||||||
if (parent.__typename === 'ContentBlockNode') {
|
if (parent.__typename === 'InstrumentNode') {
|
||||||
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 {
|
|
||||||
mutation = {
|
mutation = {
|
||||||
mutation: UPDATE_INSTRUMENT_BOOKMARK,
|
mutation: UPDATE_INSTRUMENT_BOOKMARK,
|
||||||
variables: {
|
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;
|
return mutation;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue