import { useEffect, useState } from 'react' import { ApiError } from '../api/client' import { joinRoom, listRooms } from '../api/rooms' import type { RoomListItem } from '../types' import { RoomAvatar } from './RoomAvatar' import './Modal.css' interface BrowseRoomsModalProps { onClose: () => void onJoined: (roomId: string) => void } export function BrowseRoomsModal({ onClose, onJoined }: BrowseRoomsModalProps) { const [rooms, setRooms] = useState([]) const [loading, setLoading] = useState(true) const [joiningId, setJoiningId] = useState(null) const [error, setError] = useState(null) useEffect(() => { listRooms() .then(setRooms) .catch((err) => setError(err instanceof ApiError ? err.message : String(err))) .finally(() => setLoading(false)) }, []) async function handleJoin(roomId: string) { setJoiningId(roomId) setError(null) try { await joinRoom(roomId) onJoined(roomId) } catch (err) { setError(err instanceof ApiError ? err.message : String(err)) } finally { setJoiningId(null) } } const joinable = rooms.filter((r) => !r.is_member) return (
e.stopPropagation()}>

Browse open rooms

{error &&

{error}

} {loading ? (

Loading...

) : joinable.length === 0 ? (

No open rooms to join right now.

) : ( joinable.map((room, i) => (
{room.name}
{room.description &&
{room.description}
}
)) )}
) }