import React, { useEffect } from "react"; import Message from "./Message"; import MessageInput from "./MessageInput"; import { useMatrix } from "../matrix/MatrixProvider.jsx"; import DemoLoginButton from "./DemoLoginButton.jsx"; // Default room to join (replace with your Matrix room ID) const DEFAULT_ROOM_ID = "!foundation:matrix.org"; export default function ChatArea() { const { messages, joinRoom, currentRoomId, user, login, loading } = useMatrix(); // Join the default room on login useEffect(() => { if (user && !currentRoomId) { joinRoom(DEFAULT_ROOM_ID); } }, [user, currentRoomId, joinRoom]); // Demo login handler const handleDemoLogin = () => { // Use a public Matrix test account or a known demo account // You can change these credentials as needed login("@mrpiglr:matrix.org", "Max!FTW2023!", "https://matrix.org"); }; if (!user) { return (
{loading &&
Logging in as demo user...
}
); } return (
{/* Chat Header */}
# general
🔔 📌 👥 128 🔍
{/* Messages */}
{messages && messages.length > 0 ? ( messages.map((msg, i) => ( )) ) : (
No messages yet.
)}
{/* Message Input */}
); } // Helper to convert Matrix event to Message props function matrixToMessageProps(event) { if (!event) return {}; if (event.type === "m.room.message") { return { type: "user", author: event.sender?.split(":")[0]?.replace("@", "") || "User", text: event.content?.body || "", time: new Date(event.origin_server_ts).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), avatar: event.sender?.charAt(1)?.toUpperCase() || "U", avatarBg: "from-blue-600 to-blue-900", }; } // Add system message mapping if needed return { type: "system", label: "MATRIX", text: JSON.stringify(event), className: "foundation" }; }