import { useEffect, useState } from 'react'; import { useAuthStore } from '../store/authStore'; import { useNavigate, Link } from 'react-router-dom'; import { LogOut, Plus, Folder, Loader2, Trash2, Settings, Sparkles } from 'lucide-react'; import { DashboardSettings } from '../components/DashboardSettings'; import { api } from '../lib/api'; interface Project { id: string; name: string; created_at: string; } export default function Dashboard() { const { user, profile, signOut } = useAuthStore(); const navigate = useNavigate(); const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [isSettingsOpen, setIsSettingsOpen] = useState(false); useEffect(() => { const fetchProjects = async () => { if (!user) return; try { const data = await api.getProjects(); setProjects(data.projects || []); } catch (error) { console.error(error); } setLoading(false); }; fetchProjects(); }, [user]); const handleDeleteProject = async (e: React.MouseEvent, id: string) => { e.stopPropagation(); // prevent navigating to editor if (!confirm('Are you sure you want to delete this project?')) return; try { await api.deleteProject(id); setProjects(projects.filter(p => p.id !== id)); } catch (err) { console.error('Error deleting project:', err); alert('Failed to delete project'); } }; const handleNewProject = async () => { const name = prompt('Enter a name for the new project:'); if (!name || name.trim() === '') return; try { const res = await api.saveProject({ name: name.trim(), scene_data: {} }); if (res.id) { navigate(`/editor/${res.id}`); } } catch (err) { console.error('Failed to create project', err); alert('Failed to create project'); } }; const handleSignOut = async () => { await signOut(); navigate('/'); }; const createNewProject = () => { navigate('/editor/new'); }; return (
Titan3d / Dashboard
{profile?.role === 'admin' && ( Admin Panel )}
{user?.email}

AI Credits

{profile?.api_credits ?? 0}

Storage Usage

0 / {profile?.storage_limit_mb ?? 100} MB

Total Projects

{projects.length}

Your Projects

{loading ? (
) : (
Create Blank Scene
navigate('/spark-plug')}>
Spark Plug (PDF to 3D)
{projects.map(project => (
navigate(`/editor/${project.id}`)} className="aspect-video bg-zinc-900 border border-zinc-800 rounded-2xl p-4 flex flex-col cursor-pointer hover:border-zinc-700 transition-colors group relative overflow-hidden">

{project.name}

{new Date(project.created_at).toLocaleDateString()}

))}
)}
setIsSettingsOpen(false)} />
); }