Merge branch 'hotfix/duplicate-and-delete-content-blocks-cachee' into develop

This commit is contained in:
Ramon Wenger 2023-04-06 12:38:37 +02:00
commit 264f0abc27
2 changed files with 23 additions and 9 deletions

View File

@ -159,13 +159,14 @@ const { mutate: duplicateContentBlock } = useMutation(DUPLICATE_CONTENT_BLOCK_MU
}
) => {
const id = props.parent.id;
const contentBlockId = props.contentBlock.id;
if (contentBlock) {
const query = CHAPTER_QUERY;
const variables = {
id,
};
const { chapter }: any = store.readQuery({ query, variables });
const index = chapter.contentBlocks.findIndex((contentBlock: ContentBlock) => contentBlock.id === id);
const index = chapter.contentBlocks.findIndex((contentBlock: ContentBlock) => contentBlock.id === contentBlockId);
const contentBlocks = insertAtIndex(chapter.contentBlocks, index, contentBlock);
const data = {
chapter: {
@ -199,8 +200,11 @@ const { mutate: doDeleteContentBlock } = useMutation(DELETE_CONTENT_BLOCK_MUTATI
};
const { chapter }: any = store.readQuery({ query, variables });
const index = chapter.contentBlocks.findIndex(
(contentBlock: ContentBlock) => contentBlock.id === props.parent.id
(contentBlock: ContentBlock) => contentBlock.id === props.contentBlock.id
);
if (index < 0) {
throw Error('ContentBlock not found');
}
const contentBlocks = removeAtIndex(chapter.contentBlocks, index);
const data = {
chapter: {

View File

@ -27,6 +27,16 @@ const typePolicies = {
RoomNode: {
keyFields: ['slug'],
},
ChapterNode: {
fields: {
contentBlocks: {
merge(_existing, incoming) {
// always replace the whole array
return incoming;
},
},
},
},
ModuleNode: {
fields: {
inEditMode: {