fix: FileTree expand/collapse not rendering children
- Change buildTree from .map() to for-loop to properly render children - Append expanded directory children to nodes array immediately - Fix TypeScript error by using ReactElement instead of JSX.Element - Children now render correctly when directories are expanded
This commit is contained in:
parent
0a510de487
commit
3062420e99
@ -136,16 +136,16 @@ export default function FileTree({ workspaceMode, onFileSelect }: FileTreeProps)
|
|||||||
|
|
||||||
// Build tree structure from flat entries
|
// Build tree structure from flat entries
|
||||||
const buildTree = useCallback((entries: FileTreeEntry[], depth: number = 0) => {
|
const buildTree = useCallback((entries: FileTreeEntry[], depth: number = 0) => {
|
||||||
return entries.map(entry => {
|
const nodes: JSX.Element[] = [];
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
const isExpanded = state.expandedPaths.has(entry.path);
|
const isExpanded = state.expandedPaths.has(entry.path);
|
||||||
const isLoading = state.loadingPaths.has(entry.path);
|
const isLoading = state.loadingPaths.has(entry.path);
|
||||||
const error = state.errors.get(entry.path);
|
const error = state.errors.get(entry.path);
|
||||||
const hasChildren = entry.type === 'directory';
|
const hasChildren = entry.type === 'directory';
|
||||||
const children = hasChildren && isExpanded && state.directoryCache.has(entry.path)
|
|
||||||
? buildTree(state.directoryCache.get(entry.path)!, depth + 1)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return (
|
// Render the node
|
||||||
|
nodes.push(
|
||||||
<FileTreeNode
|
<FileTreeNode
|
||||||
key={entry.path}
|
key={entry.path}
|
||||||
entry={entry}
|
entry={entry}
|
||||||
@ -158,7 +158,15 @@ export default function FileTree({ workspaceMode, onFileSelect }: FileTreeProps)
|
|||||||
onSelect={handleFileSelect}
|
onSelect={handleFileSelect}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
// If directory is expanded, render children immediately after
|
||||||
|
if (hasChildren && isExpanded && state.directoryCache.has(entry.path)) {
|
||||||
|
const children = buildTree(state.directoryCache.get(entry.path)!, depth + 1);
|
||||||
|
nodes.push(...children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
}, [state.expandedPaths, state.loadingPaths, state.errors, state.directoryCache, toggleExpand, handleFileSelect]);
|
}, [state.expandedPaths, state.loadingPaths, state.errors, state.directoryCache, toggleExpand, handleFileSelect]);
|
||||||
|
|
||||||
const rootEntries = state.directoryCache.get('') || [];
|
const rootEntries = state.directoryCache.get('') || [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user