// ui/src/components/InstanceList.tsx import { useInstances } from '@/contexts/InstancesContext' import InstanceCard from '@/components/InstanceCard' import type { Instance } from '@/types/instance' import { memo } from 'react' interface InstanceListProps { editInstance: (instance: Instance) => void } // Memoize InstanceCard to prevent re-renders when other instances change const MemoizedInstanceCard = memo(InstanceCard) function InstanceList({ editInstance }: InstanceListProps) { const { instances, loading, error, startInstance, stopInstance, deleteInstance } = useInstances() if (loading) { return (

Loading instances...

) } if (error) { return (

Error loading instances

{error}

) } if (instances.length === 0) { return (

No instances found

Create your first instance to get started

) } return (

Instances ({instances.length})

{instances.map((instance) => ( { void startInstance(instance.name) }} stopInstance={() => { void stopInstance(instance.name) }} deleteInstance={() => { void deleteInstance(instance.name) }} editInstance={editInstance} /> ))}
) } export default InstanceList