MCPcopy Create free account
hub / github.com/Fibi66/FeiControl / FileBrowser

Function FileBrowser

src/components/FileBrowser.tsx:276–774  ·  view source on GitHub ↗
({ workspace, path, onNavigate, viewMode = "list" }: FileBrowserProps)

Source from the content-addressed store, hash-verified

274
275// ─── Main FileBrowser Component ────────────────────────────────────────────────
276export function FileBrowser({ workspace, path, onNavigate, viewMode = "list" }: FileBrowserProps) {
277 const [items, setItems] = useState<FileEntry[]>([]);
278 const [loading, setLoading] = useState(true);
279 const [error, setError] = useState<string | null>(null);
280 const [previewFile, setPreviewFile] = useState<{ workspace: string; path: string; name: string } | null>(null);
281 const [editorFile, setEditorFile] = useState<{ workspace: string; path: string; name: string } | null>(null);
282 const [dragging, setDragging] = useState(false);
283 const [uploading, setUploading] = useState(false);
284 const [confirmDelete, setConfirmDelete] = useState<FileEntry | null>(null);
285 const [newFolderName, setNewFolderName] = useState("");
286 const [showNewFolder, setShowNewFolder] = useState(false);
287 const [newFileName, setNewFileName] = useState("");
288 const [showNewFile, setShowNewFile] = useState(false);
289 const [actionMenu, setActionMenu] = useState<string | null>(null);
290 const fileInputRef = useRef<HTMLInputElement>(null);
291
292 const loadItems = useCallback(() => {
293 setLoading(true);
294 setError(null);
295 fetch(`/api/browse?workspace=${encodeURIComponent(workspace)}&path=${encodeURIComponent(path)}`)
296 .then((res) => {
297 if (!res.ok) throw new Error("Failed to load directory");
298 return res.json();
299 })
300 .then((data) => {
301 setItems(data.items || []);
302 setLoading(false);
303 })
304 .catch((err) => {
305 setError(err.message);
306 setLoading(false);
307 });
308 }, [workspace, path]);
309
310 useEffect(() => {
311 loadItems();
312 }, [loadItems]);
313
314 const handleItemClick = (item: FileEntry) => {
315 if (item.type === "folder") {
316 const newPath = path ? `${path}/${item.name}` : item.name;
317 onNavigate(newPath);
318 } else {
319 const filePath = path ? `${path}/${item.name}` : item.name;
320 if (isEditable(item.name)) {
321 setEditorFile({ workspace, path: filePath, name: item.name });
322 } else {
323 setPreviewFile({ workspace, path: filePath, name: item.name });
324 }
325 }
326 };
327
328 // Upload handler
329 const handleUpload = async (files: FileList | null) => {
330 if (!files || files.length === 0) return;
331 setUploading(true);
332 try {
333 const formData = new FormData();

Callers

nothing calls this directly

Calls 10

handleUploadFunction · 0.85
handleCreateFolderFunction · 0.85
handleCreateFileFunction · 0.85
getFileColorFunction · 0.85
handleItemClickFunction · 0.85
isEditableFunction · 0.85
formatFileSizeFunction · 0.85
getFileIconFunction · 0.70
handleDownloadFunction · 0.70
handleDeleteFunction · 0.70

Tested by

no test coverage detected