Commit c398ed18 by Liu

fix:收藏返回时回到当前选中工具

parent 6a029a0e
......@@ -32,6 +32,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const [toolList, setToolList] = useState<any[]>([])
const [selectedToolId, setSelectedToolId] = useState<string | null>(null)
const [isToolBtnActive, setIsToolBtnActive] = useState<boolean>(true)
const currentToolId = useAppSelector((state: RootState) => state.conversation.currentToolId)
// 获取工具列表
const getToolList = async () => {
......@@ -50,6 +51,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}
}
// 保持当前工具状态与 Redux 中的同步,确保跨页面返回时仍保持原模式
useEffect(() => {
if (currentToolId) {
setSelectedToolId(currentToolId)
setIsToolBtnActive(false)
}
else {
setSelectedToolId(null)
setIsToolBtnActive(true)
}
}, [currentToolId])
const startAnimation = () => {
intervalRef.current = setInterval(() => {
setCurrentPlaceholder(prev => (prev + 1) % placeholders.length)
......@@ -289,7 +302,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
{tool.toolIcon && (
<img
src={tool.toolIcon}
alt={tool.toolName}
className="w-4 h-4 flex-shrink-0"
/>
)}
......
......@@ -108,6 +108,13 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
}
}, [shouldNavigateToNewConversation, currentConversationId, navigate, dispatch])
// keep latest conversation id in sessionStorage for cross-page returns (e.g., from collect)
useEffect(() => {
if (currentConversationId) {
sessionStorage.setItem('currentConversationId', currentConversationId)
}
}, [currentConversationId])
const navRef = useRef<HTMLButtonElement>(null)
useClickAway(() => {
setIsH5NavVisible(true)
......
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