mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-03 14:23:12 +00:00
"Direct Message" can lead to confusion with "Direct Connection" that refers to low latency network connections.
41 lines
849 B
TypeScript
41 lines
849 B
TypeScript
import React from 'react';
|
|
import { List, ListItem, ListItemText } from '@material-ui/core';
|
|
|
|
/**
|
|
* Clear text message
|
|
*/
|
|
export interface Message {
|
|
text: string;
|
|
timestamp: Date;
|
|
}
|
|
|
|
export interface Props {
|
|
messages: Message[];
|
|
}
|
|
|
|
export default function Messages({ messages }: Props) {
|
|
return <List dense={true}>{generate(messages)}</List>;
|
|
}
|
|
|
|
function generate(messages: Message[]) {
|
|
return messages.map((msg) => {
|
|
const text = `<${formatDisplayDate(msg.timestamp)}> ${msg.text}`;
|
|
|
|
return (
|
|
<ListItem>
|
|
<ListItemText key={formatDisplayDate(msg.timestamp)} primary={text} />
|
|
</ListItem>
|
|
);
|
|
});
|
|
}
|
|
|
|
function formatDisplayDate(timestamp: Date): string {
|
|
return timestamp.toLocaleString([], {
|
|
month: 'short',
|
|
day: 'numeric',
|
|
hour: 'numeric',
|
|
minute: '2-digit',
|
|
hour12: false,
|
|
});
|
|
}
|