MCPcopy Create free account
hub / github.com/altic-dev/Pilot / FileBrowser

Function FileBrowser

src/components/file-browser.tsx:17–183  ·  view source on GitHub ↗
({ sessionId }: FileBrowserProps)

Source from the content-addressed store, hash-verified

15}
16
17export function FileBrowser({ sessionId }: FileBrowserProps) {
18 const [files, setFiles] = useState<FileEntry[]>([]);
19 const [expandedDirs, setExpandedDirs] = useState<Set<string>>(new Set(["/workspace/repo"]));
20 const [selectedFile, setSelectedFile] = useState<string | null>(null);
21 const [fileContent, setFileContent] = useState<string | null>(null);
22 const [loading, setLoading] = useState(true);
23 const [error, setError] = useState<string | null>(null);
24
25 useEffect(() => {
26 loadDirectory("/workspace/repo");
27 }, [sessionId]);
28
29 const loadDirectory = async (dirPath: string) => {
30 try {
31 const response = await fetch(
32 `/api/container/${sessionId}/files?path=${encodeURIComponent(dirPath)}`
33 );
34
35 if (!response.ok) {
36 throw new Error("Failed to load directory");
37 }
38
39 const entries: FileEntry[] = await response.json();
40
41 // Add entries to files list (avoid duplicates)
42 setFiles((prev) => {
43 const newFiles = [...prev];
44 for (const entry of entries) {
45 if (!newFiles.some((f) => f.path === entry.path)) {
46 newFiles.push(entry);
47 }
48 }
49 return newFiles;
50 });
51
52 setLoading(false);
53 } catch (err) {
54 setError(err instanceof Error ? err.message : "Failed to load directory");
55 setLoading(false);
56 }
57 };
58
59 const toggleDirectory = async (dirPath: string) => {
60 const newExpanded = new Set(expandedDirs);
61
62 if (expandedDirs.has(dirPath)) {
63 newExpanded.delete(dirPath);
64 } else {
65 newExpanded.add(dirPath);
66 // Load directory contents if not already loaded
67 await loadDirectory(dirPath);
68 }
69
70 setExpandedDirs(newExpanded);
71 };
72
73 const selectFile = async (filePath: string) => {
74 setSelectedFile(filePath);

Callers

nothing calls this directly

Calls 2

loadDirectoryFunction · 0.85
renderTreeFunction · 0.85

Tested by

no test coverage detected