diff --git a/web-chat/src/Room.tsx b/web-chat/src/Room.tsx index 8f09914224..c3a1efe623 100644 --- a/web-chat/src/Room.tsx +++ b/web-chat/src/Room.tsx @@ -22,7 +22,7 @@ export default function Room(props: Props) { style={{ height: '100vh', display: 'flex', flexDirection: 'column' }} >
- +
{ - const renderedLines = []; +function ChatList(props: ChatListProps) { + const messages = props.messages; - for (const i in props.messages) { - renderedLines.push( - - - - ); - } + const listItems = messages.map((message) => ( + + } /> + + )); - return {renderedLines}; -}; + return {listItems}; +} -// TODO: Make it a proper component -function printMessage(chatMsg: ChatMessage) { +interface MessageProps { + message: ChatMessage; +} + +function Message(props: MessageProps) { + const chatMsg = props.message; const timestamp = chatMsg.timestamp.toLocaleString([], { month: 'short', day: 'numeric', @@ -93,5 +92,9 @@ function printMessage(chatMsg: ChatMessage) { minute: '2-digit', hour12: false, }); - return `<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`; + return ( +
+ {`<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`} +
+ ); }