Commit c01bf4c6 by weiyudumei

feat: 优化历史记录和推荐问题交互逻辑

1. 修复首页自动创建会话功能
2. 优化历史记录点击逻辑,不再自动带入最后一条问题
3. 保持产品问答和推荐问题的自动发送功能
4. 区分不同场景的shouldSendQuestion处理逻辑
parent 49fe1fae
......@@ -5,12 +5,10 @@ import { useEffect, useState } from 'react'
import { useDebounceFn } from 'ahooks'
import { containerVariants, itemVariants } from '../../motionAnimate'
import EmptyIcon from '@/assets/svg/empty.svg?react'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { useAppSelector } from '@/store/hook'
import type { Conversation } from '@/types/conversation'
import { processConversationData } from '@/store/conversationSlice.helper'
import { setShouldSendQuestion } from '@/store/conversationSlice'
import { isMobile } from '@/utils'
import { fetchUserQaRecordPage } from '@/api/conversation'
interface HistoryBarListProps {
searchValue: string
......@@ -19,36 +17,15 @@ interface HistoryBarListProps {
export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onSetHistoryVisible }) => {
const navigate = useNavigate()
const dispatch = useAppDispatch()
const { currentConversationId, conversations } = useAppSelector(state => state.conversation)
const [allItems, setAllItems] = useState<Conversation[]>([])
const handleClick = async (conversation: Conversation) => {
const handleClick = (conversation: Conversation) => {
if (isMobile()) {
onSetHistoryVisible(false)
}
try {
// 获取该对话的详细记录
const res = await fetchUserQaRecordPage(conversation.conversationId)
if (res && res.data && res.data.length > 0) {
// 获取最后一条用户问题
const lastRecord = res.data[res.data.length - 1]
if (lastRecord.question) {
// 设置shouldSendQuestion,这样用户就可以继续对话
dispatch(setShouldSendQuestion(lastRecord.question))
// 等待状态设置完成后再导航
setTimeout(() => {
navigate(`/chat/${conversation.conversationId}`)
}, 50)
return
}
}
}
catch (error) {
console.error('Failed to fetch conversation details:', error)
}
// 直接导航到历史记录,不设置shouldSendQuestion
navigate(`/chat/${conversation.conversationId}`)
}
......
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