11import type { ReactNode } from "react" ;
2- import React , { useState } from "react" ;
2+ import React , { useState , useMemo } from "react" ;
33import styled from "@emotion/styled" ;
44import type { CmuxMessage , DisplayedMessage } from "@/types/message" ;
55import { HeaderButton } from "../tools/shared/ToolPrimitives" ;
6+ import { formatTimestamp } from "@/utils/ui/dateTime" ;
67
78const MessageBlock = styled . div < { borderColor : string ; backgroundColor ?: string } > `
89 margin-bottom: 15px;
@@ -25,11 +26,23 @@ const MessageHeader = styled.div`
2526 font-weight: 500;
2627` ;
2728
29+ const LeftSection = styled . div `
30+ display: flex;
31+ align-items: center;
32+ gap: 12px;
33+ ` ;
34+
2835const MessageTypeLabel = styled . div `
2936 text-transform: uppercase;
3037 letter-spacing: 0.5px;
3138` ;
3239
40+ const TimestampText = styled . span `
41+ font-size: 10px;
42+ color: var(--color-text-secondary);
43+ font-weight: 400;
44+ ` ;
45+
3346const ButtonGroup = styled . div `
3447 display: flex;
3548 gap: 6px;
@@ -81,10 +94,23 @@ export const MessageWindow: React.FC<MessageWindowProps> = ({
8194} ) => {
8295 const [ showJson , setShowJson ] = useState ( false ) ;
8396
97+ // Get timestamp from message if available
98+ const timestamp =
99+ "timestamp" in message && typeof message . timestamp === "number" ? message . timestamp : null ;
100+
101+ // Memoize formatted timestamp to avoid recalculating on every render
102+ const formattedTimestamp = useMemo (
103+ ( ) => ( timestamp ? formatTimestamp ( timestamp ) : null ) ,
104+ [ timestamp ]
105+ ) ;
106+
84107 return (
85108 < MessageBlock borderColor = { borderColor } backgroundColor = { backgroundColor } className = { className } >
86109 < MessageHeader >
87- < MessageTypeLabel > { label } </ MessageTypeLabel >
110+ < LeftSection >
111+ < MessageTypeLabel > { label } </ MessageTypeLabel >
112+ { formattedTimestamp && < TimestampText > { formattedTimestamp } </ TimestampText > }
113+ </ LeftSection >
88114 < ButtonGroup >
89115 { rightLabel }
90116 { buttons . map ( ( button , index ) => (
0 commit comments