* feat: adding create bot functionality Signed-off-by: James <james@jan.ai> * update the temperature progress bar Signed-off-by: James <james@jan.ai> * WIP baselayout * Mapping plugins with available preferences * Added loader component * WIP working another screen * Cleanup types and avoid import one by one * Prepare bottom bar * Add css variables colors to enable user select the accent * Enable change accent color * Seperate css variable * Fix conflict * Add blank state of my model empty * Restyle explore models page * Enable user config left sidebar * Restyle my models page * WIP styling chat page * Restyling chat message * Fix conflict * Adde form preferences setting plugins * Fixed form bot info * Sidebar bot chat * Showing rightbar for both setting when user created bot * Fix style bot info * Using overflow auto intead of scroll * Remove script built UI from root package * Fix missig import * Resolve error linter * fix e2e tests Signed-off-by: James <james@jan.ai> --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
'use client'
|
|
|
|
import React, { useCallback, useRef, useState, useEffect } from 'react'
|
|
import ChatItem from '../ChatItem'
|
|
import useChatMessages from '@hooks/useChatMessages'
|
|
import { useAtomValue } from 'jotai'
|
|
import { selectAtom } from 'jotai/utils'
|
|
import { getActiveConvoIdAtom } from '@helpers/atoms/Conversation.atom'
|
|
import { chatMessages } from '@helpers/atoms/ChatMessage.atom'
|
|
|
|
const ChatBody: React.FC = () => {
|
|
const activeConversationId = useAtomValue(getActiveConvoIdAtom) ?? ''
|
|
const messageList = useAtomValue(
|
|
selectAtom(
|
|
chatMessages,
|
|
useCallback((v) => v[activeConversationId], [activeConversationId])
|
|
)
|
|
)
|
|
const [content, setContent] = useState<React.JSX.Element[]>([])
|
|
|
|
const [offset, setOffset] = useState(0)
|
|
const { loading, hasMore } = useChatMessages(offset)
|
|
const intersectObs = useRef<any>(null)
|
|
|
|
const lastPostRef = useCallback(
|
|
(message: ChatMessage) => {
|
|
if (loading) return
|
|
|
|
if (intersectObs.current) intersectObs.current.disconnect()
|
|
|
|
intersectObs.current = new IntersectionObserver((entries) => {
|
|
if (entries[0].isIntersecting && hasMore) {
|
|
setOffset((prevOffset) => prevOffset + 5)
|
|
}
|
|
})
|
|
|
|
if (message) intersectObs.current.observe(message)
|
|
},
|
|
[loading, hasMore]
|
|
)
|
|
|
|
useEffect(() => {
|
|
const list = messageList?.map((message, index) => {
|
|
if (messageList?.length === index + 1) {
|
|
return (
|
|
// @ts-ignore
|
|
<ChatItem ref={lastPostRef} message={message} key={message.id} />
|
|
)
|
|
}
|
|
return <ChatItem message={message} key={message.id} />
|
|
})
|
|
setContent(list)
|
|
}, [messageList, lastPostRef])
|
|
|
|
return (
|
|
<div className="[&>*:nth-child(odd)]:bg-background flex h-full flex-1 flex-col-reverse overflow-y-auto">
|
|
{content}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ChatBody
|