import * as DropdownMenu from '@radix-ui/react-dropdown-menu' import { Dropdown, DropdownItem } from './Dropdown' import { useState } from 'react' type Agent = { name: string, boundClientIds: string[], color: string, } export function AgentButton() { const [agents, setAgents] = useState([ { name: 'Floof der Vanderbelt', boundClientIds: ['312342'], color: '#eb4034' }, { name: 'Bark', boundClientIds: ['312342', '312343'], color: '#32d96c' }, { name: 'Meow', boundClientIds: [], color: '#3db9eb' }, ]) const [boundToAgent, setBoundToAgent] = useState('Bark') const sansYou = agents.filter((agent: Agent) => agent.name !== boundToAgent) const boundAgents = sansYou.filter((agent: Agent) => agent.boundClientIds.length > 0) const unboundAgents = sansYou.filter((agent: Agent) => agent.boundClientIds.length === 0) const you = agents.find((agent: Agent) => agent.name === boundToAgent) const handleColorChange = (name: string, color: string) => { setAgents(agents.map(agent => agent.name === name ? { ...agent, color } : agent )) } const handleDelete = (name: string) => { setAgents(agents.filter(agent => agent.name !== name)) if (boundToAgent === name) { setBoundToAgent(null) } } const handleBind = (name: string) => { setBoundToAgent(name) } const handleAdd = (e: React.MouseEvent) => { e.stopPropagation() const name = randomName() const color = randomHexColor() setAgents([...agents, { name, boundClientIds: [], color }]) } const handleRename = (name: string, newName: string) => { setBoundToAgent(newName) setAgents(agents.map(agent => agent.name === name ? { ...agent, name: newName } : agent)) } return (
{boundToAgent ? ( <> {boundToAgent}
) : 'Join'}
} > {you && handleRename(you.name, newName)} onColorChange={(color) => handleColorChange(you.name, color)} onDelete={() => handleDelete(you.name)} onBind={() => handleBind(you.name)} />} {boundAgents.map((agent: Agent) => ( handleColorChange(agent.name, color)} onDelete={() => handleDelete(agent.name)} onBind={() => handleBind(agent.name)} /> ))} {unboundAgents.map((agent: Agent) => ( handleColorChange(agent.name, color)} onDelete={() => handleDelete(agent.name)} onBind={() => handleBind(agent.name)} /> ))} handleAdd(e)} />
) } function AgentItem({ agent, isReadonly, canRename, onColorChange, onRename, onDelete, onBind }: { agent: Agent, isReadonly?: boolean, canRename?: boolean, onColorChange: (color: string) => void, onRename?: (name: string) => void, onDelete: () => void, onBind: () => void }) { return
{!isReadonly && } {canRename ? ( e.stopPropagation()} onChange={(e) => { e.preventDefault() e.stopPropagation() onRename?.(e.target.value) }} // onKeyDown={(e) => { // // e.preventDefault() // e.stopPropagation() // }} style={{ color: isReadonly ? 'grey' : 'black' }} /> ) : ( {agent.name} )}
} function AddAgentButton({ onAdd }: { onAdd: (e: React.MouseEvent) => void }) { return
Add Name +
} function Separator() { return } function ColorPicker({ color, onChange }: { color: string, onChange: (color: string) => void }) { return (
e.stopPropagation()} onChange={(e) => onChange(e.target.value)} style={{ position: 'absolute', opacity: 0, width: '100%', height: '100%', cursor: 'pointer', }} />
); } function DeleteButton({ onClick }: { onClick: () => void }) { return ( ); } function randomName(): string { const firstNames = ['Boba', 'Zap', 'Fizz', 'Glorp', 'Squish', 'Blip', 'Floof', 'Ziggy', 'Quark', 'Noodle', 'AI']; const lastNames = ['Bubbles', 'Zoomers', 'Wiggles', 'Snazzle', 'Boop', 'Fizzle', 'Wobble', 'Giggle', 'Squeak', 'Noodle', 'Palace']; return `${firstNames[Math.floor(Math.random() * firstNames.length)]} ${lastNames[Math.floor(Math.random() * lastNames.length)]}` } function randomHexColor(): string { return `#${Math.floor(Math.random() * 16777215).toString(16)}` }