Skip to content

Commit

Permalink
fix: scroll bottom when switch thread (#4152)
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur authored Nov 28, 2024
1 parent cd5e1ff commit 8657e03
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions web/containers/ListContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@ import { PropsWithChildren, useCallback, useEffect, useRef } from 'react'

import { ScrollArea } from '@janhq/joi'

import { useAtomValue } from 'jotai'

import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'

const ListContainer = ({ children }: PropsWithChildren) => {
const listRef = useRef<HTMLDivElement>(null)
const prevScrollTop = useRef(0)
const isUserManuallyScrollingUp = useRef(false)
const activeThread = useAtomValue(activeThreadAtom)
const prevActiveThread = useRef(activeThread)

// Handle active thread changes
useEffect(() => {
if (prevActiveThread.current?.id !== activeThread?.id) {
isUserManuallyScrollingUp.current = false
const scrollHeight = listRef.current?.scrollHeight ?? 0
listRef.current?.scrollTo({
top: scrollHeight,
behavior: 'instant',
})
prevActiveThread.current = activeThread // Update the previous active thread reference
}
}, [activeThread])

const handleScroll = useCallback((event: React.UIEvent<HTMLElement>) => {
const currentScrollTop = event.currentTarget.scrollTop
Expand Down

0 comments on commit 8657e03

Please sign in to comment.