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 id = props.parent.id;
const contentBlockId = props.contentBlock.id;
if (contentBlock) { if (contentBlock) {
const query = CHAPTER_QUERY; const query = CHAPTER_QUERY;
const variables = { const variables = {
id, id,
}; };
const { chapter }: any = store.readQuery({ query, variables }); 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 contentBlocks = insertAtIndex(chapter.contentBlocks, index, contentBlock);
const data = { const data = {
chapter: { chapter: {
@ -199,8 +200,11 @@ const { mutate: doDeleteContentBlock } = useMutation(DELETE_CONTENT_BLOCK_MUTATI
}; };
const { chapter }: any = store.readQuery({ query, variables }); const { chapter }: any = store.readQuery({ query, variables });
const index = chapter.contentBlocks.findIndex( 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 contentBlocks = removeAtIndex(chapter.contentBlocks, index);
const data = { const data = {
chapter: { chapter: {

View File

@ -9,13 +9,13 @@ const helloEmailVar = makeVar('');
const idToRefFactory = const idToRefFactory =
(__typename) => (__typename) =>
(_, { args, toReference }) => { (_, { args, toReference }) => {
log.debug(`Referencing ${__typename} with ${args.id}`); log.debug(`Referencing ${__typename} with ${args.id}`);
return toReference({ return toReference({
__typename, __typename,
id: args.id, id: args.id,
}); });
}; };
const typePolicies = { const typePolicies = {
ProjectNode: { ProjectNode: {
@ -27,6 +27,16 @@ const typePolicies = {
RoomNode: { RoomNode: {
keyFields: ['slug'], keyFields: ['slug'],
}, },
ChapterNode: {
fields: {
contentBlocks: {
merge(_existing, incoming) {
// always replace the whole array
return incoming;
},
},
},
},
ModuleNode: { ModuleNode: {
fields: { fields: {
inEditMode: { inEditMode: {