2022-04-30 01:09:53 +03:00
|
|
|
import { Spin } from 'antd';
|
2022-05-02 06:56:11 +03:00
|
|
|
import { Virtuoso } from 'react-virtuoso';
|
|
|
|
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
2022-04-28 09:19:20 +03:00
|
|
|
import { ChatMessage } from '../../interfaces/chat-message.model';
|
2022-04-30 01:09:53 +03:00
|
|
|
import { ChatState } from '../../interfaces/application-state';
|
2022-05-02 06:56:11 +03:00
|
|
|
import ChatUserMessage from './ChatUserMessage';
|
2022-04-28 09:19:20 +03:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
messages: ChatMessage[];
|
2022-04-30 01:09:53 +03:00
|
|
|
state: ChatState;
|
2022-04-28 09:19:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function ChatContainer(props: Props) {
|
2022-04-30 01:09:53 +03:00
|
|
|
const { messages, state } = props;
|
|
|
|
const loading = state === ChatState.Loading;
|
|
|
|
|
2022-05-02 06:56:11 +03:00
|
|
|
const chatContainerRef = useRef(null);
|
|
|
|
|
2022-04-30 01:09:53 +03:00
|
|
|
return (
|
|
|
|
<div>
|
2022-05-02 06:56:11 +03:00
|
|
|
<Spin spinning={loading} />
|
|
|
|
|
|
|
|
<Virtuoso
|
|
|
|
style={{ height: 400 }}
|
|
|
|
ref={chatContainerRef}
|
|
|
|
initialTopMostItemIndex={999}
|
|
|
|
data={messages}
|
|
|
|
itemContent={(index, message) => (
|
|
|
|
<ChatUserMessage message={message} showModeratorMenu={false} />
|
|
|
|
)}
|
|
|
|
followOutput="auto"
|
|
|
|
/>
|
2022-04-30 01:09:53 +03:00
|
|
|
</div>
|
|
|
|
);
|
2022-04-28 09:19:20 +03:00
|
|
|
}
|