import React, { useEffect, useState } from 'react' import { getShumaiClient } from '../api/client' import { ProjectCard } from '../components/ProjectCard' import { Button } from '@swc-react/button' import { ProgressCircle } from '@swc-react/progress-circle' import { IllustratedMessage } from '@swc-react/illustrated-message' import { Divider } from '@swc-react/divider' export interface ProjectSummary { id: string name: string teamId: string rootFolder?: string | null coverImage?: string | null updatedAt?: string | Date } interface ProjectsViewProps { endpoint: string apiKey: string onSelectProject: (project: ProjectSummary) => void } export const ProjectsView: React.FC = ({ endpoint, apiKey, onSelectProject, }) => { const [projects, setProjects] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchProjects = async () => { setLoading(true) setError(null) try { const client = getShumaiClient(endpoint, apiKey) const res = await client.api.projects.$get({ query: { first: '200', previewFormat: 'jpeg' }, }) if (!res.ok) { const errData = (await res.json().catch(() => ({}))) as { error?: string } throw new Error(errData.error || `Failed to fetch projects (${res.status})`) } const body = await res.json() setProjects((body.data || []) as ProjectSummary[]) } catch (err) { console.error('Error fetching projects:', err) setError(err instanceof Error ? err.message : 'Failed to load projects.') } finally { setLoading(false) } } useEffect(() => { fetchProjects() }, [endpoint, apiKey]) return (
{/* Sticky Title Bar */}

Projects

{!loading && {projects.length}}
{loading && (

Loading projects...

)} {error && !loading && (
)} {!loading && !error && projects.length === 0 && (
)} {!loading && !error && projects.length > 0 && (
{projects.map((project) => ( onSelectProject(project)} /> ))}
)}
) }