import { useEffect, useState } from 'react'; import { useThreadStore, type Thread } from '../stores/thread.ts'; interface ThreadListPanelProps { channelId: string; onSelect: (thread: { id: string; name: string }) => void; onClose: () => void; } export function ThreadListPanel({ channelId, onSelect, onClose }: ThreadListPanelProps) { const threads = useThreadStore((s) => s.threadsByParent[channelId] || []); const fetchThreads = useThreadStore((s) => s.fetchThreads); const createThread = useThreadStore((s) => s.createThread); const [name, setName] = useState(''); const [loading, setLoading] = useState(false); useEffect(() => { fetchThreads(channelId); }, [channelId, fetchThreads]); const handleCreate = async () => { if (!name.trim()) return; setLoading(true); try { const t = await createThread(channelId, { name: name.trim() }); onSelect({ id: t.id, name: t.name }); setName(''); } finally { setLoading(false); } }; return (
THREADS
setName(e.target.value)} placeholder="new thread name" className="terminal-input flex-1 text-xs" />
{threads.length === 0 &&
[no threads]
}
{threads.map((t: Thread) => ( ))}
); }