Fix scroll behavior

This commit is contained in:
Saoud Rizwan
2024-09-13 03:42:09 -04:00
parent 0c8fbb11d8
commit 0f914b1bf0

View File

@@ -431,28 +431,31 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
if (isCollapsing && isAtBottom) {
const timer = setTimeout(() => {
if (virtuosoRef.current) {
virtuosoRef.current.scrollToIndex({
virtuosoRef.current?.scrollToIndex({
index: visibleMessages.length - 1,
align: "end",
})
}
}, 0)
return () => clearTimeout(timer)
}
if (!isCollapsing && isLastMessage) {
} else if (isLastMessage) {
if (isCollapsing) {
const timer = setTimeout(() => {
if (virtuosoRef.current) {
virtuosoRef.current.scrollToIndex({
virtuosoRef.current?.scrollToIndex({
index: visibleMessages.length - 1,
align: "end",
})
}, 0)
return () => clearTimeout(timer)
} else {
const timer = setTimeout(() => {
virtuosoRef.current?.scrollToIndex({
index: visibleMessages.length - 1,
align: "start",
behavior: "smooth",
})
}
}, 0)
return () => clearTimeout(timer)
}
}
},
[isAtBottom, visibleMessages, expandedRows]
)