(id: string)
| 282 | ); |
| 283 | |
| 284 | const loadChildren = async (id: string) => { |
| 285 | const currentNode = nodesById.get(id); |
| 286 | if (currentNode == null || !currentNode.isDirectory || currentNode.notfound || currentNode.staterror || fetchDir == null) { |
| 287 | return; |
| 288 | } |
| 289 | const status = currentNode.childrenStatus ?? "unloaded"; |
| 290 | if (status !== "unloaded") { |
| 291 | return; |
| 292 | } |
| 293 | setNodesById((prev) => { |
| 294 | const next = new Map(prev); |
| 295 | next.set(id, { ...currentNode, childrenStatus: "loading" }); |
| 296 | return next; |
| 297 | }); |
| 298 | try { |
| 299 | const result = await fetchDir(id, maxDirEntries); |
| 300 | setNodesById((prev) => { |
| 301 | const next = new Map(prev); |
| 302 | result.nodes.forEach((node) => { |
| 303 | const merged: TreeNodeData = { |
| 304 | ...node, |
| 305 | parentId: node.parentId ?? id, |
| 306 | childrenStatus: node.childrenStatus ?? (node.isDirectory ? "unloaded" : "loaded"), |
| 307 | }; |
| 308 | next.set(merged.id, merged); |
| 309 | }); |
| 310 | const childrenIds = sortIdsByNode( |
| 311 | next, |
| 312 | result.nodes.map((entry) => entry.id) |
| 313 | ); |
| 314 | const source = next.get(id) ?? currentNode; |
| 315 | next.set(id, { |
| 316 | ...source, |
| 317 | childrenIds, |
| 318 | childrenStatus: result.capped ? "capped" : "loaded", |
| 319 | capInfo: result.capped ? { max: maxDirEntries, totalKnown: result.totalKnown } : undefined, |
| 320 | }); |
| 321 | return next; |
| 322 | }); |
| 323 | } catch (error) { |
| 324 | setNodesById((prev) => { |
| 325 | const next = new Map(prev); |
| 326 | const source = next.get(id) ?? currentNode; |
| 327 | next.set(id, { |
| 328 | ...source, |
| 329 | childrenStatus: "error", |
| 330 | staterror: error instanceof Error ? error.message : "Unknown error", |
| 331 | }); |
| 332 | return next; |
| 333 | }); |
| 334 | } |
| 335 | }; |
| 336 | |
| 337 | const toggleExpand = (id: string) => { |
| 338 | const node = nodesById.get(id); |
no test coverage detected