Skip to content

Commit

Permalink
fix: scroll bottom when switch thread
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Nov 28, 2024
1 parent 7bd59f0 commit 2a1d292
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({

Check warning on line 21 in web/containers/ListContainer/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

19-21 lines are not covered with tests
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

Check warning on line 30 in web/containers/ListContainer/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

30 line is not covered with tests
Expand Down

0 comments on commit 2a1d292

Please sign in to comment.