Commit 86e1cdf8 by Liu

fix:推荐问新建会话逻辑

parent 12e28b73
......@@ -3,10 +3,11 @@ import type React from 'react'
import { Image } from '@heroui/image'
import { motion } from 'framer-motion'
import { useCallback, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import Refresh from '@/assets/svg/refresh.svg?react'
import { type WithAuthProps, withAuth } from '@/auth/withAuth'
import { useAppDispatch } from '@/store/hook'
import { createConversation } from '@/store/conversationSlice'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { createConversation, setCurrentConversation, setShouldSendQuestion } from '@/store/conversationSlice'
import emptyIcon from '@/assets/empty-icon.png'
interface QuestionListProps {
......@@ -72,6 +73,8 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
const [displayedItems, setDisplayedItems] = useState<string[]>([])
const [isClicking, setIsClicking] = useState(false)
const dispatch = useAppDispatch()
const navigate = useNavigate()
const { currentConversationId, conversations } = useAppSelector(state => state.conversation)
// 根据 isToolBtn 动态设置 displayCount
const actualDisplayCount = isToolBtn ? 6 : 4
......@@ -89,13 +92,29 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
const handleClick = (item: string) => {
if (checkAuth() && !isClicking) {
setIsClicking(true)
dispatch(
createConversation({
conversationData: {},
shouldNavigate: true,
shouldSendQuestion: item,
}),
)
// 优先使用当前会话,如果没有则使用第一个会话,如果都没有则创建新会话
const targetConversationId = currentConversationId || conversations[0]?.conversationId
if (targetConversationId) {
// 使用现有会话
dispatch(setCurrentConversation(targetConversationId))
dispatch(setShouldSendQuestion(item))
navigate(`/chat/${targetConversationId}`)
}
else {
// 如果没有现有会话,仍然创建新会话(向后兼容)
// 这里可以改为提示用户,或者保持创建新会话的逻辑
// 为了最小修改,暂时保持创建新会话的逻辑
dispatch(
createConversation({
conversationData: {},
shouldNavigate: true,
shouldSendQuestion: item,
}),
)
}
// 防止重复点击
setTimeout(() => {
setIsClicking(false)
......
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