Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #182 from tipisai/improve/message-list
Browse files Browse the repository at this point in the history
feat: improve message list scroll timing
  • Loading branch information
Wangtaofeng authored May 7, 2024
2 parents 5294909 + 557d002 commit 1bfaa60
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions apps/agent/src/components/PreviewChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const PreviewChat: FC<PreviewChatProps> = (props) => {

const scrollDirectRef = useRef<SCROLL_DIRECTION>(SCROLL_DIRECTION.DOWN)
const cacheLastScroll = useRef<number>(0)
const cacheMessageLength = useRef(chatMessages.length)

const handleClickStopGenerating = useCallback(() => {
TipisTrack.track("click_stop_generate")
Expand All @@ -58,20 +57,15 @@ export const PreviewChat: FC<PreviewChatProps> = (props) => {
}

useEffect(() => {
if (chatMessages.length === 0) {
scrollDirectRef.current = SCROLL_DIRECTION.DOWN
}
if (scrollDirectRef.current === SCROLL_DIRECTION.DOWN) {
if (
!!currentRenderMessage &&
scrollDirectRef.current === SCROLL_DIRECTION.DOWN
) {
chatRef.current?.scrollTo({
top: chatRef.current.scrollHeight,
})
} else {
if (cacheMessageLength.current !== chatMessages.length) {
scrollDirectRef.current = SCROLL_DIRECTION.DOWN
}
}
cacheMessageLength.current = chatMessages.length
}, [chatMessages])
}, [currentRenderMessage])

return (
<div css={previewChatContainerStyle}>
Expand Down

0 comments on commit 1bfaa60

Please sign in to comment.