fix wrong tree sync bug (#514)

This commit is contained in:
Philip Okugbe 2024-11-28 19:39:38 +00:00 committed by GitHub
parent f178e6654f
commit 311d81bc71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 19 deletions

View File

@ -191,7 +191,7 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
<div ref={mergedRef} className={classes.treeContainer}>
{rootElement.current && (
<Tree
data={data}
data={data.filter((node) => node?.spaceId === spaceId)}
disableDrag={readOnly}
disableDrop={readOnly}
disableEdit={readOnly}

View File

@ -46,30 +46,34 @@ export const useTreeSocket = () => {
break;
case 'moveTreeNode':
// move node
treeApi.move({
id: event.payload.id,
parentId: event.payload.parentId,
index: event.payload.index
});
if (treeApi.find(event.payload.id)) {
treeApi.move({
id: event.payload.id,
parentId: event.payload.parentId,
index: event.payload.index
});
// update node position
treeApi.update({
id: event.payload.id,
changes: {
position: event.payload.position,
}
});
// update node position
treeApi.update({
id: event.payload.id,
changes: {
position: event.payload.position,
}
});
setTreeData(treeApi.data);
setTreeData(treeApi.data);
}
break;
case "deleteTreeNode":
treeApi.drop({ id: event.payload.node.id });
setTreeData(treeApi.data);
if (treeApi.find(event.payload.node.id)){
treeApi.drop({ id: event.payload.node.id });
setTreeData(treeApi.data);
queryClient.invalidateQueries({
queryKey: ['pages', event.payload.node.slugId].filter(Boolean),
});
queryClient.invalidateQueries({
queryKey: ['pages', event.payload.node.slugId].filter(Boolean),
});
}
break;
}
});