diff --git a/src/pages/RepoPage/shared/components/FileExplorerState/FileExplorerState.tsx b/src/pages/RepoPage/shared/components/FileExplorerState/FileExplorerState.tsx new file mode 100644 index 0000000000..cec15272d3 --- /dev/null +++ b/src/pages/RepoPage/shared/components/FileExplorerState/FileExplorerState.tsx @@ -0,0 +1,91 @@ +import { useEffect, useState } from 'react' + +interface FileItem { + name: string + type: 'file' | 'dir' + path: string +} + +interface FileExplorerStateProps { + initialPath?: string + files: FileItem[] + onPathChange?: (path: string) => void +} + +export function FileExplorerState({ + initialPath = '', + files, + onPathChange, +}: FileExplorerStateProps) { + const [currentPath, setCurrentPath] = useState(initialPath) + const [pathMetadata, setPathMetadata] = useState({ + path: initialPath, + visited: false, + }) + + useEffect(() => { + if (initialPath) { + setPathMetadata({ path: initialPath, visited: false }) + } + }, [initialPath, pathMetadata]) + + useEffect(() => { + if (onPathChange) { + onPathChange(currentPath) + } + }, [onPathChange, currentPath]) + + const handleDirectoryClick = (dirPath: string) => { + setCurrentPath(dirPath) + } + + const handleBackClick = () => { + const parentPath = currentPath.split('/').slice(0, -1).join('/') + setCurrentPath(parentPath) + } + + return ( +
+
+ {currentPath && ( + + )} + + {currentPath || '/'} + +
+ +
+ {files + .filter((item) => item.path.startsWith(currentPath)) + .map((item) => ( +
+ + {item.type === 'dir' ? '📁' : '📄'} + + {item.type === 'dir' ? ( + + ) : ( + {item.name} + )} +
+ ))} +
+
+ ) +} + +export default FileExplorerState