3f52167b04
Phase 2 of issue 0001. uniweb becomes a pure frontend (web/ only), like unibus_android: the SPA talks directly to the bus and the Go gateway is gone. - busService.ts: the new data layer over the bus SDK, replacing the old api module. It holds the user's wallet identity and a connected BusClient IN THE BROWSER and opens the session locally — the private key is never sent anywhere (closes the gateway-era hole where the browser POSTed its private key to /api/session). - Wire account/App/ChatShell/ChatPanel/WalletLogin/Recover/Join to busService; subscribeRoom replaces the SSE streamRoom; ApiError -> SessionError. - SDK: ControlPlane.createRoom + listMemberRooms, and fetchRoom mapped to the real control-plane wire shape (snake_case, no id) — all verified by the live round-trip. - Delete cmd/webgw, go.mod, go.sum, src/api.ts and the orphan operator Login. uniweb now has zero Go and no dependency on unibus as a module. - vite: drop the /api proxy, dev server on 5173 to match the bus CORS allowlist; add vite-env typings. app.md: lang ts, no uses_functions, e2e_checks are now web-only. Bump 0.3.0. Onboarding by token is now admin-side (the bus has no self-register endpoint; the gateway only mocked it). tsc + pnpm build + 19/19 unit green.
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
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<Room[]>([]);
|
|
const [activeId, setActiveId] = useState<string>("");
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(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 = <ChatPanel room={active} />;
|
|
if (loading && rooms.length === 0) {
|
|
panel = (
|
|
<Center h="100%">
|
|
<Loader color="brand" />
|
|
</Center>
|
|
);
|
|
} else if (error) {
|
|
panel = (
|
|
<Center h="100%">
|
|
<Stack align="center" gap="sm">
|
|
<Text c="red" size="sm">
|
|
{error}
|
|
</Text>
|
|
<Button variant="light" color="brand" onClick={load}>
|
|
Reintentar
|
|
</Button>
|
|
</Stack>
|
|
</Center>
|
|
);
|
|
} else if (rooms.length === 0) {
|
|
panel = (
|
|
<Center h="100%">
|
|
<Text c="dimmed">No perteneces a ninguna room todavía</Text>
|
|
</Center>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Flex h="100vh" w="100vw" style={{ overflow: "hidden" }}>
|
|
<Box
|
|
w={320}
|
|
h="100%"
|
|
bg="dark.8"
|
|
style={{
|
|
borderRight: "1px solid var(--mantine-color-dark-4)",
|
|
flexShrink: 0,
|
|
}}
|
|
>
|
|
<Sidebar
|
|
user={user}
|
|
rooms={rooms}
|
|
activeId={activeId}
|
|
onSelect={setActiveId}
|
|
onLogout={onLogout}
|
|
/>
|
|
</Box>
|
|
<Box flex={1} h="100%" bg="dark.7" style={{ minWidth: 0 }}>
|
|
{panel}
|
|
</Box>
|
|
</Flex>
|
|
);
|
|
}
|