mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-04 20:00:00 +08:00
fix(sessions): reset topic fulfilled state when switching sessions
Reset the topic fulfilled state when switching between sessions to ensure proper state management. Also remove redundant state update from SessionItem's onPress handler.
This commit is contained in:
parent
aadadf8353
commit
bc0f283278
@ -14,7 +14,7 @@ import { AgentSessionEntity } from '@renderer/types'
|
|||||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@renderer/ui/context-menu'
|
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@renderer/ui/context-menu'
|
||||||
import { buildAgentSessionTopicId } from '@renderer/utils/agentSession'
|
import { buildAgentSessionTopicId } from '@renderer/utils/agentSession'
|
||||||
import { XIcon } from 'lucide-react'
|
import { XIcon } from 'lucide-react'
|
||||||
import React, { FC, memo, startTransition, useMemo, useState } from 'react'
|
import React, { FC, memo, startTransition, useEffect, useMemo, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
@ -97,6 +97,12 @@ const SessionItem: FC<SessionItemProps> = ({ session, agentId, isDisabled, isLoa
|
|||||||
const isPending = useMemo(() => topicLoadingQuery[sessionTopicId], [sessionTopicId, topicLoadingQuery])
|
const isPending = useMemo(() => topicLoadingQuery[sessionTopicId], [sessionTopicId, topicLoadingQuery])
|
||||||
const isFulfilled = useMemo(() => topicFulfilledQuery[sessionTopicId], [sessionTopicId, topicFulfilledQuery])
|
const isFulfilled = useMemo(() => topicFulfilledQuery[sessionTopicId], [sessionTopicId, topicFulfilledQuery])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isFulfilled && activeSessionId === session.id) {
|
||||||
|
dispatch(newMessagesActions.setTopicFulfilled({ topicId: sessionTopicId, fulfilled: false }))
|
||||||
|
}
|
||||||
|
}, [activeSessionId, dispatch, isFulfilled, session.id, sessionTopicId])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ContextMenu modal={false}>
|
<ContextMenu modal={false}>
|
||||||
@ -104,10 +110,7 @@ const SessionItem: FC<SessionItemProps> = ({ session, agentId, isDisabled, isLoa
|
|||||||
<ButtonContainer
|
<ButtonContainer
|
||||||
isDisabled={isDisabled}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
onPress={() => {
|
onPress={onPress}
|
||||||
dispatch(newMessagesActions.setTopicFulfilled({ topicId: sessionTopicId, fulfilled: false }))
|
|
||||||
onPress()
|
|
||||||
}}
|
|
||||||
isActive={isActive}
|
isActive={isActive}
|
||||||
onDoubleClick={() => startEdit(session.name ?? '')}
|
onDoubleClick={() => startEdit(session.name ?? '')}
|
||||||
className="group">
|
className="group">
|
||||||
|
|||||||
@ -4,12 +4,14 @@ import { useAgent } from '@renderer/hooks/agents/useAgent'
|
|||||||
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
||||||
import { useRuntime } from '@renderer/hooks/useRuntime'
|
import { useRuntime } from '@renderer/hooks/useRuntime'
|
||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
|
import { newMessagesActions } from '@renderer/store/newMessage'
|
||||||
import {
|
import {
|
||||||
setActiveSessionIdAction,
|
setActiveSessionIdAction,
|
||||||
setActiveTopicOrSessionAction,
|
setActiveTopicOrSessionAction,
|
||||||
setSessionWaitingAction
|
setSessionWaitingAction
|
||||||
} from '@renderer/store/runtime'
|
} from '@renderer/store/runtime'
|
||||||
import { CreateSessionForm } from '@renderer/types'
|
import { CreateSessionForm } from '@renderer/types'
|
||||||
|
import { buildAgentSessionTopicId } from '@renderer/utils/agentSession'
|
||||||
import { AnimatePresence, motion } from 'framer-motion'
|
import { AnimatePresence, motion } from 'framer-motion'
|
||||||
import { Plus } from 'lucide-react'
|
import { Plus } from 'lucide-react'
|
||||||
import { memo, useCallback, useEffect } from 'react'
|
import { memo, useCallback, useEffect } from 'react'
|
||||||
@ -80,6 +82,17 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
|||||||
}
|
}
|
||||||
}, [isLoading, sessions, currentActiveSessionId, agentId, setActiveSessionId])
|
}, [isLoading, sessions, currentActiveSessionId, agentId, setActiveSessionId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentActiveSessionId) {
|
||||||
|
dispatch(
|
||||||
|
newMessagesActions.setTopicFulfilled({
|
||||||
|
topicId: buildAgentSessionTopicId(currentActiveSessionId),
|
||||||
|
fulfilled: false
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}, [currentActiveSessionId, dispatch])
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user