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) { if (isCollapsing && isAtBottom) {
const timer = setTimeout(() => { const timer = setTimeout(() => {
if (virtuosoRef.current) { virtuosoRef.current?.scrollToIndex({
virtuosoRef.current.scrollToIndex({
index: visibleMessages.length - 1, index: visibleMessages.length - 1,
align: "end", align: "end",
}) })
}
}, 0) }, 0)
return () => clearTimeout(timer) return () => clearTimeout(timer)
} } else if (isLastMessage) {
if (isCollapsing) {
if (!isCollapsing && isLastMessage) {
const timer = setTimeout(() => { 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, index: visibleMessages.length - 1,
align: "start", align: "start",
behavior: "smooth",
}) })
}
}, 0) }, 0)
return () => clearTimeout(timer) return () => clearTimeout(timer)
} }
}
}, },
[isAtBottom, visibleMessages, expandedRows] [isAtBottom, visibleMessages, expandedRows]
) )