import {
Card,
CardContent,
List,
ListItem,
ListItemText,
Typography,
} from '@material-ui/core';
import React, { useEffect, useRef } from 'react';
import { ChatMessage } from '../../build/main/chat/chat_message';
interface Props {
messages: ChatMessage[];
}
export default function ChatList(props: Props) {
const messages = props.messages;
const listItems = messages.map((message) => (
} />
));
return (
{listItems}
);
}
interface MessageProps {
message: ChatMessage;
}
function Message(props: MessageProps) {
const chatMsg = props.message;
const timestamp = chatMsg.timestamp.toLocaleString([], {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: false,
});
// {`<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`}
return (
{chatMsg.nick}
{timestamp}
{chatMsg.message}
);
}
const AlwaysScrollToBottom = (props: Props) => {
const elementRef = useRef();
useEffect(() => {
// @ts-ignore
elementRef.current.scrollIntoView();
}, [props.messages]);
// @ts-ignore
return ;
};