MCPcopy Create free account
hub / github.com/esengine/esengine / toggleNode

Function toggleNode

packages/editor-app/src/components/FileTree.tsx:325–358  ·  view source on GitHub ↗
(nodePath: string)

Source from the content-addressed store, hash-verified

323 };
324
325 const toggleNode = async (nodePath: string) => {
326 const updateTree = async (nodes: TreeNode[]): Promise<TreeNode[]> => {
327 const newNodes: TreeNode[] = [];
328 for (const node of nodes) {
329 if (node.path === nodePath) {
330 if (!node.loaded) {
331 const children = await loadChildren(node);
332 newNodes.push({
333 ...node,
334 expanded: true,
335 loaded: true,
336 children
337 });
338 } else {
339 newNodes.push({
340 ...node,
341 expanded: !node.expanded
342 });
343 }
344 } else if (node.children) {
345 newNodes.push({
346 ...node,
347 children: await updateTree(node.children)
348 });
349 } else {
350 newNodes.push(node);
351 }
352 }
353 return newNodes;
354 };
355
356 const newTree = await updateTree(tree);
357 setTree(newTree);
358 };
359
360 const refreshTree = async () => {
361 if (!rootPath) return;

Callers 1

handleNodeClickFunction · 0.85

Calls 1

updateTreeFunction · 0.85

Tested by

no test coverage detected