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.
This commit is contained in:
Asurada
2025-03-19 16:29:56 +08:00
committed by GitHub
parent 2e9c9ef0bd
commit 0656ed4bfe
@@ -31,11 +31,13 @@ const Assistants: FC<AssistantsTabProps> = ({
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 (