import React, { useEffect, useState } from 'react'; import { api } from '../../services/api'; export default function FileExplorer({ onSelectFile, activeFile }) { const [files, setFiles] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { loadFiles(); }, []); const loadFiles = async () => { setLoading(true); try { const data = await api.getFiles(); setFiles(Array.isArray(data) ? data : []); } catch (err) { console.error("Failed to load workspace files:", err); } finally { setLoading(false); } }; return (
Explorer
{loading ? (
Loading tree...
) : files.length === 0 ? (
No files found.
) : ( files.map((file) => (
onSelectFile(file.path || file.name)} className={`px-3 py-1.5 rounded cursor-pointer flex items-center gap-2 transition-colors ${ activeFile === (file.path || file.name) ? 'bg-blue-600 text-white font-medium' : 'hover:bg-slate-800 text-slate-300' }`} > {file.is_dir ? '📁' : '📄'} {file.name || file.path}
)) )}
); }