-
- {!isOwn && (
- {message.author.name}
- )}
- {timestamp}
- {isOwn && (
- {message.author.name}
- )}
-
-
- {isEditing ? (
-
- ) : (
-
- {message.content}
-
- )}
- {isOwn && !isEditing && (
-
-
- •
-
-
- )}
-
-
- );
-}
-
-export default React.memo(ChatMessageDisplay);
diff --git a/client/src/components/ChatMessage/ChatMessageDisplay.tsx b/client/src/components/ChatMessage/ChatMessageDisplay.tsx
new file mode 100644
index 0000000..dbea6bd
--- /dev/null
+++ b/client/src/components/ChatMessage/ChatMessageDisplay.tsx
@@ -0,0 +1,81 @@
+import React, { useState } from "react";
+import { ChatMessage } from "../../../../shared";
+import MessageHeader from "./MessageHeader";
+import MessageEditForm from "./MessageEditForm";
+import MessageActions from "./MessageActions";
+
+function ChatMessageDisplay({
+ message,
+ userId,
+ onDelete,
+ onEdit,
+}: {
+ message: ChatMessage;
+ userId: string | undefined;
+ onDelete: (messageId: string) => void;
+ onEdit: (messageId: string, newContent: string) => void;
+}) {
+ const [isEditing, setIsEditing] = useState(false);
+ const [editContent, setEditContent] = useState(message.content);
+ const isOwn = userId === message.author.userId;
+
+ const timestamp = new Date(message.timestamp).toLocaleTimeString([], {
+ hour: "2-digit",
+ minute: "2-digit",
+ });
+
+ const handleSave = () => {
+ if (editContent.trim() !== message.content) {
+ onEdit(message.id, editContent);
+ }
+ setIsEditing(false);
+ };
+
+ const handleCancel = () => {
+ setEditContent(message.content);
+ setIsEditing(false);
+ };
+
+ return (
+
+
+
setName(e.target.value)}
onKeyDown={handleKeyPress}
+ aria-required="true"
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
/>
-
diff --git a/client/src/components/Layout.tsx b/client/src/components/Layout.tsx
index f1d8c4d..043a5b1 100644
--- a/client/src/components/Layout.tsx
+++ b/client/src/components/Layout.tsx
@@ -6,10 +6,12 @@ function Layout({ children }: LayoutProps) {
return (
<>
-
+
- {children}
+
+ {children}
+
>
);
diff --git a/client/src/components/MessageDisplay.tsx b/client/src/components/MessageDisplay.tsx
index 4748fb0..7eb71cd 100644
--- a/client/src/components/MessageDisplay.tsx
+++ b/client/src/components/MessageDisplay.tsx
@@ -6,7 +6,7 @@ import {
ServerMessage,
} from "../../../shared";
import { useChatState } from "../contexts/ChatContext";
-import ChatMessage from "./ChatMessage";
+import ChatMessageDisplay from "./ChatMessage/ChatMessageDisplay";
interface MessageDisplayProps {
sendMessage: (message: ClientMessage) => void;
@@ -56,7 +56,7 @@ function ChatMessages({ sendMessage }: MessageDisplayProps) {
switch (message.type) {
case "CHAT_MESSAGE":
return (
-
-