refactor: good bye react-scroll-to-bottom (#2769)
Co-authored-by: James <james@jan.ai>
This commit is contained in:
parent
b058dda8bb
commit
da6c648e47
29
web/containers/ListContainer/index.tsx
Normal file
29
web/containers/ListContainer/index.tsx
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { ReactNode, useEffect, useRef } from 'react'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children: ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
const ListContainer: React.FC<Props> = ({ children }) => {
|
||||||
|
const listRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const scrollHeight = listRef.current?.scrollHeight ?? 0
|
||||||
|
|
||||||
|
listRef.current?.scrollTo({
|
||||||
|
top: scrollHeight,
|
||||||
|
behavior: 'smooth',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={listRef}
|
||||||
|
className="flex h-full w-full flex-col overflow-y-scroll"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ListContainer
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import ScrollToBottom from 'react-scroll-to-bottom'
|
|
||||||
|
|
||||||
import { MessageStatus } from '@janhq/core'
|
import { MessageStatus } from '@janhq/core'
|
||||||
import { useAtomValue } from 'jotai'
|
import { useAtomValue } from 'jotai'
|
||||||
|
|
||||||
|
import ListContainer from '@/containers/ListContainer'
|
||||||
|
|
||||||
import { loadModelErrorAtom } from '@/hooks/useActiveModel'
|
import { loadModelErrorAtom } from '@/hooks/useActiveModel'
|
||||||
|
|
||||||
import ChatItem from '../ChatItem'
|
import ChatItem from '../ChatItem'
|
||||||
@ -26,7 +26,7 @@ const ChatBody: React.FC = () => {
|
|||||||
if (messages.length === 0) return <EmptyThread />
|
if (messages.length === 0) return <EmptyThread />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollToBottom className="flex h-full w-full flex-col">
|
<ListContainer>
|
||||||
{messages.map((message, index) => (
|
{messages.map((message, index) => (
|
||||||
<div key={message.id}>
|
<div key={message.id}>
|
||||||
{message.status !== MessageStatus.Error &&
|
{message.status !== MessageStatus.Error &&
|
||||||
@ -43,7 +43,7 @@ const ChatBody: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{loadModelError && <LoadModelError />}
|
{loadModelError && <LoadModelError />}
|
||||||
</ScrollToBottom>
|
</ListContainer>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user