Improve chat container bottom scrolling handling. Closes #2342

This commit is contained in:
Gabe Kangas
2023-02-18 11:58:46 -08:00
parent 835a644de0
commit 564d058e2e
2 changed files with 61 additions and 24 deletions

View File

@@ -1,7 +1,6 @@
import { Button } from 'antd';
import dynamic from 'next/dynamic';
import { FC, MutableRefObject } from 'react';
import { ChatMessage } from '../../../interfaces/chat-message.model';
import { FC } from 'react';
import styles from './ChatContainer.module.scss';
// Lazy loaded components
@@ -12,23 +11,18 @@ const VerticalAlignBottomOutlined = dynamic(
ssr: false,
},
);
type Props = {
chatContainerRef: MutableRefObject<any>;
messages: ChatMessage[];
onClick: () => void;
};
export const ScrollToBotBtn: FC<Props> = ({ chatContainerRef, messages }) => (
export const ScrollToBotBtn: FC<Props> = ({ onClick }) => (
<div className={styles.toBottomWrap}>
<Button
type="default"
style={{ color: 'currentColor' }}
icon={<VerticalAlignBottomOutlined />}
onClick={() =>
chatContainerRef.current.scrollToIndex({
index: messages.length - 1,
behavior: 'auto',
})
}
onClick={onClick}
>
Go to last message
</Button>