import React, { useEffect, useState } from 'react'; import { Box, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Typography, Divider, CircularProgress } from '@mui/material'; import { Storage } from '@mui/icons-material'; import { useAppStore } from '../store/useAppStore'; import { SchemaService } from '../services/api'; const Sidebar: React.FC = () => { const { activeDatabase, setActiveDatabase, setActiveTable, activeTable } = useAppStore(); const [databases, setDatabases] = useState([]); const [tables, setTables] = useState([]); const [loading, setLoading] = useState(true); const [tablesLoading, setTablesLoading] = useState(false); useEffect(() => { const fetchDatabases = async () => { try { const response = await SchemaService.getDatabases(); setDatabases(response.data); } catch (error) { console.error('Failed to fetch databases', error); } finally { setLoading(false); } }; fetchDatabases(); }, []); const handleDatabaseClick = async (db: string) => { if (activeDatabase === db) { setActiveDatabase(null); setTables([]); return; } setActiveDatabase(db); setTablesLoading(true); try { const response = await SchemaService.getTables(db); setTables(response.data); } catch (error) { console.error('Failed to fetch tables', error); } finally { setTablesLoading(false); } }; return ( Explorer {loading ? ( ) : ( {databases.map((db) => ( handleDatabaseClick(db)} selected={activeDatabase === db} sx={{ py: 1 }} > {db}} /> {activeDatabase === db && ( {tablesLoading ? ( ) : tables.length === 0 ? ( No tables found ) : tables.map((table) => ( setActiveTable(table)} sx={{ py: 0.5 }} > {table}} /> ))} )} ))} )} Connected to: 127.0.0.1 ); }; export default Sidebar;