import { useState } from "react"; import type { Channel } from "@/types/Channel"; import { createChannel, getCurrentUsername } from "@/api"; interface Props { channels: Channel[]; activeId: string | null; onSelect: (id: string) => void; onChannelCreated: () => void; } export function ChannelSidebar({ channels, activeId, onSelect, onChannelCreated, }: Props) { const [newName, setNewName] = useState(""); const [creating, setCreating] = useState(false); async function handleCreate() { if (!newName.trim()) return; setCreating(true); await createChannel({ name: newName.trim(), description: "" }); setNewName(""); setCreating(false); onChannelCreated(); } return (
{/* Header */}
COLONY
apes.unslope.com
{/* Channel list */}
CHANNELS
{channels.map((ch) => ( ))}
{/* Current user */}
logged in as {getCurrentUsername()}
{/* New channel input */}
setNewName(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleCreate()} disabled={creating} className="w-full bg-sidebar-accent text-[11px] text-sidebar-foreground placeholder:text-muted-foreground px-2 py-1 rounded-sm border border-sidebar-border focus:outline-none focus:border-[var(--color-agent-glow)]" />
); }