diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e6b3729..8127713 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -19,11 +19,17 @@ export function App({ socket }: AppProps) { const [roomID, setRoomID] = useState(""); const [rooms, setRooms] = useState([]); const [joinedRooms, setJoinedRooms] = useState>(new Set()); +// <<<<<< codex/update-chat-bubble-alignment + const [messagesByRoom, setMessagesByRoom] = useState>({}); + const [userName] = useState(() => createGuestName()); + const [userToken] = useState(() => crypto.randomUUID()); +// ======= const [messagesByRoom, setMessagesByRoom] = useState>({}); const [isConnected, setIsConnected] = useState(false); const hasSentConnect = useRef(false); const pendingTimers = useRef>(new Map()); const identity = useMemo(() => createIdentity(), []); +// >>>>>>> main const handleListRooms = useCallback((response: Response) => { if (response.type === "list_rooms") { @@ -146,8 +152,22 @@ export function App({ socket }: AppProps) { }, []); const sendMessageRequest = useWsRequest(socket, undefined); + const connectRequest = useWsRequest(socket, undefined); + + useEffect(() => { + if (!socket) { + return; + } + + connectRequest({ type: "connect", token: userToken, name: userName }); + }, [connectRequest, socket, userName, userToken]); const onMessageSent = (content: string) => { +// <<<<<< codex/update-chat-bubble-alignment + const chat: Chat = { content, user: { name: userName } }; + +// ======= +// >>>>>>> main if (!roomID) { return; } @@ -215,12 +235,29 @@ export function App({ socket }: AppProps) { return ( <> - {roomID ? : } + {roomID ? ( + + ) : ( + + )} ); } +// <<<<<< codex/update-chat-bubble-alignment +function createGuestName(): string { + const adjectives = ["Amber", "Brisk", "Golden", "Quiet", "Sandy", "Silver", "Sunny", "Velvet"]; + const nouns = ["Comet", "Dawn", "Drift", "Ember", "Harbor", "Horizon", "Lumen", "Spark"]; + const adjective = adjectives[Math.floor(Math.random() * adjectives.length)]; + const noun = nouns[Math.floor(Math.random() * nouns.length)]; + const suffix = Math.floor(100 + Math.random() * 900); + return `${adjective}${noun}${suffix}`; +// ====== function createIdentity(): Identity { const token = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : fallbackId(); return { @@ -238,4 +275,5 @@ function createMessageId(): string { function fallbackId(): string { return Math.random().toString(36).slice(2, 10); +// >>>>>> main } diff --git a/frontend/src/ChatPanel.tsx b/frontend/src/ChatPanel.tsx index 8e5f726..05b1b41 100644 --- a/frontend/src/ChatPanel.tsx +++ b/frontend/src/ChatPanel.tsx @@ -9,11 +9,16 @@ export type ChatMessage = { }; type ChatPanelProps = { +// <<<<< codex/update-chat-bubble-alignment + currentUserName: string; + messages: Chat[]; +//======= messages: ChatMessage[]; +// >>>>>>> main onMessageSent: (message: string) => void; }; -export function ChatPanel({ messages, onMessageSent }: ChatPanelProps) { +export function ChatPanel({ currentUserName, messages, onMessageSent }: ChatPanelProps) { const [draft, setDraft] = useState(""); return ( @@ -21,6 +26,22 @@ export function ChatPanel({ messages, onMessageSent }: ChatPanelProps) {

Chat

+// <<<<< codex/update-chat-bubble-alignment + {messages.map((message, index) => { + const isOwnMessage = message.user.name === currentUserName; + const chatAlignment = isOwnMessage ? "chat-end" : "chat-start"; + const bubbleTone = isOwnMessage ? "chat-bubble-primary" : "chat-bubble-secondary"; + const footerText = isOwnMessage ? "Sent" : "Delivered"; + + return ( +
+
+ {isOwnMessage ? "You" : (message.user.name ?? "Anonymous")} + +
+
{message.content}
+
{footerText}
+// ======= {messages.map((message) => { const bubbleClass = message.status === "pending" @@ -39,6 +60,7 @@ export function ChatPanel({ messages, onMessageSent }: ChatPanelProps) { {message.status === "error" ? (
Delivery failed
) : null} +// >>>>>> main
); })}