owncast/web/components/chat/ChatContainer/ChatContainer.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Spin } from 'antd';
import { Virtuoso } from 'react-virtuoso';
2022-05-12 09:31:31 +03:00
import { useRef } from 'react';
2022-05-04 00:17:05 +03:00
import { LoadingOutlined } from '@ant-design/icons';
2022-05-22 16:05:40 +03:00
import { ChatMessage } from '../../../interfaces/chat-message.model';
import { ChatState } from '../../../interfaces/application-state';
import { MessageType } from '../../../interfaces/socket-events';
import s from './ChatContainer.module.scss';
2022-05-22 17:10:34 +03:00
import { ChatUserMessage } from '..';
interface Props {
messages: ChatMessage[];
state: ChatState;
}
export default function ChatContainer(props: Props) {
const { messages, state } = props;
const loading = state === ChatState.Loading;
const chatContainerRef = useRef(null);
2022-05-04 00:17:05 +03:00
const spinIcon = <LoadingOutlined style={{ fontSize: '32px' }} spin />;
const getViewForMessage = message => {
switch (message.type) {
case MessageType.CHAT:
return <ChatUserMessage message={message} showModeratorMenu={false} />;
default:
return null;
}
};
return (
<div>
<div className={s.chatHeader}>
<span>stream chat</span>
</div>
<Spin spinning={loading} indicator={spinIcon} />
<Virtuoso
style={{ height: '80vh' }}
ref={chatContainerRef}
initialTopMostItemIndex={999}
data={messages}
2022-05-04 00:17:05 +03:00
itemContent={(index, message) => getViewForMessage(message)}
followOutput="smooth"
/>
</div>
);
}