Commit cbf58826 by HoMeTown

feat: 新建会话首次发送消息刷新会话列表

parent c4b8c5a6
import { Button, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow, getKeyValue } from '@nextui-org/react'
import React from 'react'
import { useDispatch } from 'react-redux'
import { useAppSelector } from '@/store/hook'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { deleteConversations } from '@/store/conversationSlice'
import useToast from '@/hooks/useToast'
......@@ -11,7 +10,7 @@ interface ConversationModalProps {
}
export const ConversationModal: React.FC<ConversationModalProps> = ({ isOpen, onClose }) => {
const dispatch = useDispatch()
const dispatch = useAppDispatch()
const showToast = useToast()
const tableColumns = [
......
......@@ -3,7 +3,6 @@ import { useParams } from 'react-router-dom'
import { Spinner } from '@nextui-org/react'
import { Virtuoso } from 'react-virtuoso'
import { motion } from 'framer-motion'
import { useDispatch, useSelector } from 'react-redux'
import styles from './Chat.module.less'
import { ChatSlogan } from './components/ChatSlogan'
import { ChatMaskBar } from './components/ChatMaskBar'
......@@ -16,18 +15,20 @@ import { ChatEditor } from '@/components/ChatEditor'
import type { ChatRecord } from '@/types/chat'
import { fetchUserQaRecordPage } from '@/api/conversation'
import { fetchCheckTokenApi, fetchStreamResponse } from '@/api/chat'
import { clearShouldSendQuestion } from '@/store/conversationSlice'
import { clearShouldSendQuestion, fetchConversations } from '@/store/conversationSlice'
import type { RootState } from '@/store' // 假设你的 store 文件导出了 RootState 类型
import { useAppDispatch, useAppSelector } from '@/store/hook'
export const Chat: React.FC = () => {
let ignore = false
const { id } = useParams<{ id: string }>()
const [isLoading, setIsLoading] = useState(false)
const [isNewConversation, setIsNewConversation] = useState(false)
const [allItems, setAllItems] = useState<ChatRecord[]>([])
const dispatch = useDispatch()
const shouldSendQuestion = useSelector((state: RootState) => state.conversation.shouldSendQuestion)
const dispatch = useAppDispatch()
const shouldSendQuestion = useAppSelector((state: RootState) => state.conversation.shouldSendQuestion)
const handleSubmitQuestion = useCallback(async (question: string) => {
const handleSubmitQuestion = async (question: string) => {
// 添加用户提问的问题
setAllItems(prevItems => [
...prevItems,
......@@ -80,14 +81,22 @@ export const Chat: React.FC = () => {
return newItems
})
}
if (msg.type === 'END') {
if (isNewConversation) {
setTimeout(() => {
dispatch(fetchConversations())
}, 2000)
}
}
},
)
}, [])
}
const getUserQaRecordPage = useCallback(async (conversationId: string) => {
setIsLoading(true)
try {
const res = await fetchUserQaRecordPage(conversationId)
setIsNewConversation(res.data.length === 0)
const messages = [{ role: 'system' } as ChatRecord, ...processApiResponse(res.data)]
setAllItems(messages) // 假设 API 返回的数据结构符合 ChatRecord[]
if (shouldSendQuestion) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment