feat: websocket rooms (#515)

This commit is contained in:
Philip Okugbe
2024-11-28 18:53:29 +00:00
committed by GitHub
parent d97baf5824
commit a16d5d1bf4
5 changed files with 79 additions and 33 deletions

View File

@ -133,13 +133,13 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
flatTreeItems = [
...flatTreeItems,
...children.filter(
(child) => !flatTreeItems.some((item) => item.id === child.id),
(child) => !flatTreeItems.some((item) => item.id === child.id)
),
];
};
const fetchPromises = ancestors.map((ancestor) =>
fetchAndUpdateChildren(ancestor),
fetchAndUpdateChildren(ancestor)
);
// Wait for all fetch operations to complete
@ -153,7 +153,7 @@ export default function SpaceTree({ spaceId, readOnly }: SpaceTreeProps) {
const updatedTree = appendNodeChildren(
data,
rootChild.id,
rootChild.children,
rootChild.children
);
setData(updatedTree);
@ -248,7 +248,7 @@ function Node({ node, style, dragHandle, tree }: NodeRendererProps<any>) {
const updatedTreeData = appendNodeChildren(
treeData,
node.data.id,
childrenTree,
childrenTree
);
setTreeData(updatedTreeData);
@ -279,6 +279,7 @@ function Node({ node, style, dragHandle, tree }: NodeRendererProps<any>) {
setTimeout(() => {
emit({
operation: "updateOne",
spaceId: node.data.spaceId,
entity: ["pages"],
id: node.id,
payload: { icon: emoji.native },
@ -293,6 +294,7 @@ function Node({ node, style, dragHandle, tree }: NodeRendererProps<any>) {
setTimeout(() => {
emit({
operation: "updateOne",
spaceId: node.data.spaceId,
entity: ["pages"],
id: node.id,
payload: { icon: null },

View File

@ -75,18 +75,19 @@ export function useTreeMutation<T>(spaceId: string) {
setTimeout(() => {
emit({
operation: "addTreeNode",
spaceId: spaceId,
payload: {
parentId,
index,
data
}
data,
},
});
}, 50);
const pageUrl = buildPageUrl(
spaceSlug,
createdPage.slugId,
createdPage.title,
createdPage.title
);
navigate(pageUrl);
return data;
@ -156,18 +157,16 @@ export function useTreeMutation<T>(spaceId: string) {
// check if the previous still has children
// if no children left, change 'hasChildren' to false, to make the page toggle arrows work properly
const childrenCount = previousParent.children.filter(
(child) => child.id !== draggedNodeId,
(child) => child.id !== draggedNodeId
).length;
if (childrenCount === 0) {
tree.update({
id: previousParent.id,
changes: { ... previousParent.data, hasChildren: false } as any,
changes: { ...previousParent.data, hasChildren: false } as any,
});
}
}
//console.log()
setData(tree.data);
const payload: IMovePage = {
@ -182,7 +181,13 @@ export function useTreeMutation<T>(spaceId: string) {
setTimeout(() => {
emit({
operation: "moveTreeNode",
payload: { id: draggedNodeId, parentId: args.parentId, index: args.index, position: newPosition },
spaceId: spaceId,
payload: {
id: draggedNodeId,
parentId: args.parentId,
index: args.index,
position: newPosition,
},
});
}, 50);
} catch (error) {
@ -214,17 +219,17 @@ export function useTreeMutation<T>(spaceId: string) {
setData(tree.data);
// navigate only if the current url is same as the deleted page
if (pageSlug && node.data.slugId === pageSlug.split('-')[1]) {
if (pageSlug && node.data.slugId === pageSlug.split("-")[1]) {
navigate(getSpaceUrl(spaceSlug));
}
setTimeout(() => {
emit({
operation: "deleteTreeNode",
payload: { node: node.data }
spaceId: spaceId,
payload: { node: node.data },
});
}, 50);
} catch (error) {
console.error("Failed to delete page:", error);
}