From f0b0bd8959ce93b81c7a691642694d2d375124a7 Mon Sep 17 00:00:00 2001 From: Asurada <43401755+ousugo@users.noreply.github.com> Date: Wed, 19 Mar 2025 16:29:56 +0800 Subject: [PATCH] fix: ensure active assistant is updated correctly on deletion (#3588) - Modified the assistant deletion logic to check if the deleted assistant is the currently active one before updating the active assistant state. This prevents potential issues when the active assistant is removed. --- src/renderer/src/pages/home/Tabs/AssistantsTab.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx b/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx index 93f9480421..4b3312ac0d 100644 --- a/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx @@ -31,11 +31,13 @@ const Assistants: FC = ({ const onDelete = useCallback( (assistant: Assistant) => { const remaining = assistants.filter((a) => a.id !== assistant.id) - const newActive = remaining[remaining.length - 1] - newActive ? setActiveAssistant(newActive) : onCreateDefaultAssistant() + if (assistant.id === activeAssistant?.id) { + const newActive = remaining[remaining.length - 1] + newActive ? setActiveAssistant(newActive) : onCreateDefaultAssistant() + } removeAssistant(assistant.id) }, - [assistants, removeAssistant, setActiveAssistant, onCreateDefaultAssistant] + [activeAssistant, assistants, removeAssistant, setActiveAssistant, onCreateDefaultAssistant] ) return (