mirror of https://github.com/waku-org/js-waku.git
Make message a component
This commit is contained in:
parent
5635ca028b
commit
243a9aba77
|
@ -22,7 +22,7 @@ export default function Room(props: Props) {
|
||||||
style={{ height: '100vh', display: 'flex', flexDirection: 'column' }}
|
style={{ height: '100vh', display: 'flex', flexDirection: 'column' }}
|
||||||
>
|
>
|
||||||
<div className="chat-list" style={{ flexGrow: 1, overflow: 'scroll' }}>
|
<div className="chat-list" style={{ flexGrow: 1, overflow: 'scroll' }}>
|
||||||
<Lines messages={props.lines} />
|
<ChatList messages={props.lines} />
|
||||||
</div>
|
</div>
|
||||||
<div className="chat-input" style={{ flexGrow: 0, height: '120px' }}>
|
<div className="chat-input" style={{ flexGrow: 0, height: '120px' }}>
|
||||||
<MessageInput
|
<MessageInput
|
||||||
|
@ -63,29 +63,28 @@ async function handleMessage(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LinesProps {
|
interface ChatListProps {
|
||||||
messages: ChatMessage[];
|
messages: ChatMessage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Lines = (props: LinesProps) => {
|
function ChatList(props: ChatListProps) {
|
||||||
const renderedLines = [];
|
const messages = props.messages;
|
||||||
|
|
||||||
for (const i in props.messages) {
|
const listItems = messages.map((message) => (
|
||||||
renderedLines.push(
|
<ListItem key={message.timestamp.toString()}>
|
||||||
<ListItem>
|
<ListItemText primary={<Message message={message} />} />
|
||||||
<ListItemText
|
</ListItem>
|
||||||
key={'chat-message-' + i}
|
));
|
||||||
primary={printMessage(props.messages[i])}
|
|
||||||
/>
|
|
||||||
</ListItem>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return <List dense={true}>{renderedLines}</List>;
|
return <List dense={true}>{listItems}</List>;
|
||||||
};
|
}
|
||||||
|
|
||||||
// TODO: Make it a proper component
|
interface MessageProps {
|
||||||
function printMessage(chatMsg: ChatMessage) {
|
message: ChatMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Message(props: MessageProps) {
|
||||||
|
const chatMsg = props.message;
|
||||||
const timestamp = chatMsg.timestamp.toLocaleString([], {
|
const timestamp = chatMsg.timestamp.toLocaleString([], {
|
||||||
month: 'short',
|
month: 'short',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
|
@ -93,5 +92,9 @@ function printMessage(chatMsg: ChatMessage) {
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
hour12: false,
|
hour12: false,
|
||||||
});
|
});
|
||||||
return `<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`;
|
return (
|
||||||
|
<div className="chat-message">
|
||||||
|
{`<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue