Add datetime for chat

This commit is contained in:
Samuele E. Locatelli
2025-08-22 17:28:28 +00:00
parent 37b1dbb618
commit eeb9df4ccf
4 changed files with 173 additions and 9 deletions
+32 -4
View File
@@ -1,10 +1,9 @@
// UserMessage.jsx
// src/UserMessage.jsx
import React from "react";
export default function UserMessage({ content, theme }) {
export default function UserMessage({ content, theme, timestamp }) {
return (
// This outer div aligns the *bubble* to the right
<div className="mb-2 d-flex justify-content-end">
<div className="mb-2 d-flex flex-column align-items-end">
<div
className={`p-2 rounded ${theme.userBg}`}
style={{
@@ -24,8 +23,37 @@ export default function UserMessage({ content, theme }) {
{content}
</pre>
</div>
{timestamp && (
<div
style={{
fontSize: "0.75rem",
color: "#666",
marginTop: "0.2rem",
marginRight: "0.25rem"
}}
>
{formatDateTime(timestamp)}
</div>
)}
</div>
);
}
// Same helper used in AssistantMessage
function formatDateTime(dateTime) {
try {
const date = new Date(dateTime);
return date.toLocaleString(undefined, {
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
});
} catch {
return dateTime;
}
}