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
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,6 +46,7 @@ export const useTreeSocket = () => {
break;
case 'moveTreeNode':
// move node
if (treeApi.find(event.payload.id)) {
treeApi.move({
id: event.payload.id,
parentId: event.payload.parentId,
@ -61,15 +62,18 @@ export const useTreeSocket = () => {
});
setTreeData(treeApi.data);
}
break;
case "deleteTreeNode":
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),
});
}
break;
}
});