From ae10c14cc8eca027708e492e8106e8112eec176e Mon Sep 17 00:00:00 2001 From: Atridad Lahiji Date: Sun, 27 Apr 2025 10:53:03 -0600 Subject: [PATCH] Chat changes --- islands/Chat.tsx | 31 +++++++++++++++++-------------- islands/NavigationBar.tsx | 11 +++++------ routes/chat.tsx | 15 ++++++++++----- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/islands/Chat.tsx b/islands/Chat.tsx index 0f4ab4d..dbc5e71 100644 --- a/islands/Chat.tsx +++ b/islands/Chat.tsx @@ -36,6 +36,7 @@ export default function Chat() { } else { setMessages((prev) => [...prev, data]); + // Auto-scroll to bottom on new message const chatBox = document.getElementById("chat-messages"); if (chatBox) { setTimeout(() => { @@ -73,19 +74,21 @@ export default function Chat() { }; return ( -
+
+ {/* Header */}
-

Live Chat

-

+

Live Chat

+

{isConnected ? `${userCount} online • Messages are not saved` : "Connecting..."}

+ {/* Chat messages area */}
{messages.length === 0 ? ( @@ -97,7 +100,7 @@ export default function Chat() { messages.map((msg, i) => (
@@ -112,44 +115,44 @@ export default function Chat() { {msg.sender === username ? "You" : msg.sender} - + {new Date(msg.timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", })}
-

{msg.text}

+

{msg.text}

)) )}
-
-
+ {/* Input area */} +
+ setNewMessage(e.currentTarget.value)} placeholder="Type your message..." - class="flex-1 px-4 py-3 bg-gray-800 text-white rounded-l-lg border-0 focus:outline-none focus:ring-2 focus:ring-secondary placeholder-gray-500" + class="w-full pl-4 pr-20 py-3 bg-gray-800 text-white rounded-lg border-0 focus:outline-none focus:ring-1 focus:ring-secondary placeholder-gray-500" disabled={!isConnected} - maxLength={2000} /> -
+

You are chatting as{" "} {username}

- +
); } diff --git a/islands/NavigationBar.tsx b/islands/NavigationBar.tsx index c06b9a0..359f8df 100644 --- a/islands/NavigationBar.tsx +++ b/islands/NavigationBar.tsx @@ -1,4 +1,3 @@ -// islands/NavigationBar.tsx import { useComputed, useSignal } from "@preact/signals"; import { useEffect } from "preact/hooks"; import { @@ -54,8 +53,8 @@ export default function NavigationBar({ currentPath }: NavigationBarProps) { isScrolling.value ? "opacity-30" : "opacity-100" } ${isVisible.value ? "translate-y-0" : "translate-y-20"}`} > -