import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { useBotStore, type StoreBot } from '../stores/bot.ts'; import { useServerStore } from '../stores/server.ts'; import { useAuthStore } from '../stores/auth.ts'; export function BotStore() { const storeBots = useBotStore((s) => s.storeBots); const loading = useBotStore((s) => s.loading); const error = useBotStore((s) => s.error); const fetchStoreBots = useBotStore((s) => s.fetchStoreBots); const addToServer = useBotStore((s) => s.addToServer); const servers = useServerStore((s) => s.servers); const fetchServers = useServerStore((s) => s.fetchServers); const currentUserId = useAuthStore((s) => s.user?.id); const [addBotId, setAddBotId] = useState(null); const [selectedServer, setSelectedServer] = useState(''); const [adding, setAdding] = useState(false); const [search, setSearch] = useState(''); useEffect(() => { fetchStoreBots(); fetchServers(); }, [fetchStoreBots, fetchServers]); const handleAdd = async () => { if (!addBotId || !selectedServer) return; setAdding(true); try { await addToServer(addBotId, selectedServer); setAddBotId(null); setSelectedServer(''); fetchStoreBots(); // refresh counts } catch { // error in store } finally { setAdding(false); } }; const filtered = storeBots.filter((b) => b.name.toLowerCase().includes(search.toLowerCase()) || b.description.toLowerCase().includes(search.toLowerCase()) ); return (
            {'┌──────────────────────────────────┐\n'}
            {'│       === BOT STORE ===          │\n'}
            {'└──────────────────────────────────┘'}
          

browse and add bots to your servers

{error && (

ERR: {error}

)} {/* Search */}
setSearch(e.target.value)} placeholder="search bots..." className="terminal-input w-full" />
{/* Bot list */} {loading && storeBots.length === 0 && (

[loading...]

)} {!loading && filtered.length === 0 && (

[no bots found]

)}
{filtered.map((bot) => ( { setAddBotId(bot.id); setSelectedServer(''); }} /> ))}
{/* Add to server modal */} {addBotId && (

{'>'} ADD BOT TO SERVER

)} {/* Footer */}
{'<'} [BACK TO CHAT] [MY BOTS]
); } function StoreBotCard({ bot, isOwner, onAdd }: { bot: StoreBot; isOwner: boolean; onAdd: () => void }) { return (

{bot.avatar && ( )} [{bot.name}] {isOwner && ( (yours) )}

{bot.description && (

{bot.description}

)}

{bot.server_count} {bot.server_count === 1 ? 'server' : 'servers'}

); }