import { useState } from "react"; import { Stack, TextInput, Checkbox, Button, Divider, Text, NavLink, ScrollArea, Group, Box, } from "@mantine/core"; import { IconLock, IconHash, IconPlus, IconDoorEnter } from "@tabler/icons-react"; import type { Room } from "../types"; interface Props { rooms: Room[]; activeRoom: string | null; onSelect: (roomID: string) => void; onCreateRoom: (subject: string, encrypt: boolean) => void; onJoinRoom: (roomID: string) => void; } // RoomList is the navbar: create a room, join one by id, and pick the active // room from the peer's known rooms. export function RoomList({ rooms, activeRoom, onSelect, onCreateRoom, onJoinRoom }: Props) { const [subject, setSubject] = useState("room.general"); const [encrypt, setEncrypt] = useState(true); const [joinID, setJoinID] = useState(""); const create = () => { if (subject.trim()) onCreateRoom(subject.trim(), encrypt); }; const join = () => { if (joinID.trim()) { onJoinRoom(joinID.trim()); setJoinID(""); } }; return ( Crear room } value={subject} onChange={(e) => setSubject(e.currentTarget.value)} onKeyDown={(e) => e.key === "Enter" && create()} /> setEncrypt(e.currentTarget.checked)} /> Unirse por id setJoinID(e.currentTarget.value)} onKeyDown={(e) => e.key === "Enter" && join()} style={{ flex: 1 }} /> Rooms ({rooms.length}) {rooms.length === 0 && ( Aún no hay rooms. Crea o únete a una. )} {rooms.map((r) => ( onSelect(r.room_id)} label={r.subject} description={r.room_id.slice(0, 14) + "…"} leftSection={ r.encrypt ? : } variant="filled" /> ))} ); }