-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.tsx
More file actions
32 lines (29 loc) · 1.01 KB
/
index.tsx
File metadata and controls
32 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import clsx from 'clsx';
import styles from './styles.module.scss';
import { observer } from 'mobx-react-lite';
import TextMessage from '..';
import DocumentRoot from '@tdev-models/DocumentRoot';
import { DocumentType } from '@tdev-api/document';
interface Props {
group: DocumentRoot<'dynamic_document_root'>;
}
const Conversation = observer((props: Props) => {
const { group } = props;
const ref = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (ref.current) {
ref.current.scrollTo({ behavior: 'smooth', top: ref.current.scrollHeight });
}
}, [ref, group.allDocuments.length]);
return (
<div className={clsx(styles.conversation)} ref={ref}>
{group.allDocuments
.filter((msg) => msg.type === 'text_message')
.map((message, index) => {
return <TextMessage key={index} message={message} />;
})}
</div>
);
});
export default Conversation;