Fixed scrolling to bottom when writing on chat
This commit is contained in:
parent
919ae5f325
commit
20cc70db36
1 changed files with 11 additions and 1 deletions
|
|
@ -33,8 +33,15 @@ export default function ChatModal({
|
||||||
const ws = useRef<WebSocket | null>(null);
|
const ws = useRef<WebSocket | null>(null);
|
||||||
const [lockChat, setLockChat] = useState(false);
|
const [lockChat, setLockChat] = useState(false);
|
||||||
const isOpen = useRef(open);
|
const isOpen = useRef(open);
|
||||||
|
const messagesRef = useRef(null);
|
||||||
const id = useRef(flow.id);
|
const id = useRef(flow.id);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (messagesRef.current) {
|
||||||
|
messagesRef.current.scrollTop = messagesRef.current.scrollHeight;
|
||||||
|
}
|
||||||
|
}, [chatHistory]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isOpen.current = open;
|
isOpen.current = open;
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
@ -401,7 +408,10 @@ export default function ChatModal({
|
||||||
<HiX className="w-5 h-5" />
|
<HiX className="w-5 h-5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full h-full bg-white dark:bg-gray-800 border-t dark:border-t-gray-600 flex-col flex items-center overflow-scroll scrollbar-hide">
|
<div
|
||||||
|
ref={messagesRef}
|
||||||
|
className="w-full h-full bg-white dark:bg-gray-800 border-t dark:border-t-gray-600 flex-col flex items-center overflow-scroll scrollbar-hide"
|
||||||
|
>
|
||||||
{chatHistory.length > 0 ? (
|
{chatHistory.length > 0 ? (
|
||||||
chatHistory.map((c, i) => (
|
chatHistory.map((c, i) => (
|
||||||
<ChatMessage lockChat={lockChat} chat={c} key={i} />
|
<ChatMessage lockChat={lockChat} chat={c} key={i} />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue