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:
@@ -14,7 +14,7 @@ import { AgentSessionEntity } from '@renderer/types'
|
||||
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@renderer/ui/context-menu'
|
||||
import { buildAgentSessionTopicId } from '@renderer/utils/agentSession'
|
||||
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 styled from 'styled-components'
|
||||
|
||||
@@ -97,6 +97,12 @@ const SessionItem: FC<SessionItemProps> = ({ session, agentId, isDisabled, isLoa
|
||||
const isPending = useMemo(() => topicLoadingQuery[sessionTopicId], [sessionTopicId, topicLoadingQuery])
|
||||
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 (
|
||||
<>
|
||||
<ContextMenu modal={false}>
|
||||
@@ -104,10 +110,7 @@ const SessionItem: FC<SessionItemProps> = ({ session, agentId, isDisabled, isLoa
|
||||
<ButtonContainer
|
||||
isDisabled={isDisabled}
|
||||
isLoading={isLoading}
|
||||
onPress={() => {
|
||||
dispatch(newMessagesActions.setTopicFulfilled({ topicId: sessionTopicId, fulfilled: false }))
|
||||
onPress()
|
||||
}}
|
||||
onPress={onPress}
|
||||
isActive={isActive}
|
||||
onDoubleClick={() => startEdit(session.name ?? '')}
|
||||
className="group">
|
||||
|
||||
@@ -4,12 +4,14 @@ import { useAgent } from '@renderer/hooks/agents/useAgent'
|
||||
import { useSessions } from '@renderer/hooks/agents/useSessions'
|
||||
import { useRuntime } from '@renderer/hooks/useRuntime'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { newMessagesActions } from '@renderer/store/newMessage'
|
||||
import {
|
||||
setActiveSessionIdAction,
|
||||
setActiveTopicOrSessionAction,
|
||||
setSessionWaitingAction
|
||||
} from '@renderer/store/runtime'
|
||||
import { CreateSessionForm } from '@renderer/types'
|
||||
import { buildAgentSessionTopicId } from '@renderer/utils/agentSession'
|
||||
import { AnimatePresence, motion } from 'framer-motion'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { memo, useCallback, useEffect } from 'react'
|
||||
@@ -80,6 +82,17 @@ const Sessions: React.FC<SessionsProps> = ({ agentId }) => {
|
||||
}
|
||||
}, [isLoading, sessions, currentActiveSessionId, agentId, setActiveSessionId])
|
||||
|
||||
useEffect(() => {
|
||||
if (currentActiveSessionId) {
|
||||
dispatch(
|
||||
newMessagesActions.setTopicFulfilled({
|
||||
topicId: buildAgentSessionTopicId(currentActiveSessionId),
|
||||
fulfilled: false
|
||||
})
|
||||
)
|
||||
}
|
||||
}, [currentActiveSessionId, dispatch])
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<motion.div
|
||||
|
||||
Reference in New Issue
Block a user