import { useCallback, useEffect, useState } from "react"; import { Flex, Box, Center, Loader, Stack, Text, Button } from "@mantine/core"; import { Sidebar } from "./Sidebar"; import { ChatPanel } from "./ChatPanel"; import { bus } from "./busService"; import type { Room, User } from "./types"; export function ChatShell({ user, onLogout, }: { user: User; onLogout: () => void; }) { const [rooms, setRooms] = useState([]); const [activeId, setActiveId] = useState(""); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const load = useCallback(() => { setLoading(true); bus .listRooms() .then((rs) => { setRooms(rs); setActiveId((cur) => cur || rs[0]?.id || ""); setError(null); }) .catch((e) => setError(e?.message ?? "No se pudieron cargar las rooms")) .finally(() => setLoading(false)); }, []); useEffect(() => { load(); }, [load]); const active = rooms.find((r) => r.id === activeId); // El panel derecho muestra el estado de carga/error/empty sin tocar el layout. let panel = ; if (loading && rooms.length === 0) { panel = (
); } else if (error) { panel = (
{error}
); } else if (rooms.length === 0) { panel = (
No perteneces a ninguna room todavĂ­a
); } return ( {panel} ); }