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 9ca46ee3d3
commit b89213b1ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,11 +31,13 @@ const Assistants: FC<AssistantsTabProps> = ({
const onDelete = useCallback( const onDelete = useCallback(
(assistant: Assistant) => { (assistant: Assistant) => {
const remaining = assistants.filter((a) => a.id !== assistant.id) const remaining = assistants.filter((a) => a.id !== assistant.id)
if (assistant.id === activeAssistant?.id) {
const newActive = remaining[remaining.length - 1] const newActive = remaining[remaining.length - 1]
newActive ? setActiveAssistant(newActive) : onCreateDefaultAssistant() newActive ? setActiveAssistant(newActive) : onCreateDefaultAssistant()
}
removeAssistant(assistant.id) removeAssistant(assistant.id)
}, },
[assistants, removeAssistant, setActiveAssistant, onCreateDefaultAssistant] [activeAssistant, assistants, removeAssistant, setActiveAssistant, onCreateDefaultAssistant]
) )
return ( return (